Linux set up to achieve asynchronous execution of HttpRunnerManager, scheduled tasks and task monitoring

Foreword

Before build HttpRunnerManager interface test platform, we still have not achieved some of the features, such as asynchronous execution, scheduled tasks, task monitoring, to complete asynchronous execution, the need to build RabbitMQenvironmental, today we have to implement these functions.

Need to prepare in advance on Linux environment (The following is the environment when I set up):
1, HttpRunnerManager (refer to the article: Linux build HttpRunnerManager interface test platform under )
2, RabbitMQ 3.7.6 (refer to article: install RabbitMQ under Linux )

Example implementation with

HttpRunnerManager, the modules and project use cases selected to be synchronous or asynchronous mode, when not building RabbitMQ environment, we can only be performed by executing a synchronized way, report back immediately after the execution.

Example implementation with

If you select asynchronous mode is performed in the background, after asynchronous execution is completed, we can go to view or download the test report. But if there is no building RabbitMQ environment, the asynchronous execution will complain, and not a test report.

Asynchronous execution error

Start RabbitMQ service

First, to achieve asynchronous execution, we need to start RabbitMQ services, and ensure normal access to its Web console management interface, as follows:

RabbitMQ main interface

Modify settings.py configuration

We simply need to modify settings.pythe configuration file, you need to modify the place as follows ( about 155 lines or so in the settings.py ):

before fixing

You can be modified through vim command as follows (modified according to their actual conditions) after the modification:

Modified

Description:

  • admin:123456Is RabbitMQthe user name and password
  • 192.168.89.128Is rabbitmq-serverwhere the server ip address
  • 5672 是RabbitMQ启动时的默认端口,注意不是 15672 端口,15672是Web控制台管理界面的访问端口。

启动worker

在 HttpRunnerManager 的根目录( manage.py 所在的路径),通过以下命令启动worker

python3 manage.py celery -A HttpRunnerManager worker --loglevel=info

也可以通过后台执行的方式启动 worker

nohup python3 manage.py celery -A HttpRunnerManager worker --loglevel=info >worker.log 2>&1 &

如果是在后台运行 worker 的日志,将输出到 worker.log 下。

tornado报错

我在启动 worker 时,遇到了如下问题:

tornado error

在网上查了下,发现是因为 tornado 版本太高了,tornado6之后版本就弃用了 tornado.web.asynchronous 这种写法,查看当前 tornado 的版本,命令如下:

pip3 show tornado

View tornado version

查看后发现 tornado 版本为 6.0.3 ,于是尝试网上说的将 tornado 降级回到 5.1.1 版本,命令如下:

卸载已安装的tornado版本:pip3 uninstall tornado
安装指定的tornado版本:pip3 install tornado==5.1.1

[root@bogon HttpRunnerManager-master]# pip3 uninstall tornado
Uninstalling tornado-6.0.3:
  Would remove:
    /root/python36/lib/python3.6/site-packages/tornado-6.0.3-py3.6.egg-info
    /root/python36/lib/python3.6/site-packages/tornado/*
Proceed (y/n)? y
  Successfully uninstalled tornado-6.0.3
[root@bogon HttpRunnerManager-master]# pip3 install tornado==5.1.1
Collecting tornado==5.1.1
  Downloading https://files.pythonhosted.org/packages/e6/78/6e7b5af12c12bdf38ca9bfe863fcaf53dc10430a312d0324e76c1e5ca426/tornado-5.1.1.tar.gz (516kB)
    100% |████████████████████████████████| 522kB 874kB/s 
Installing collected packages: tornado
  Running setup.py install for tornado ... done
Successfully installed tornado-5.1.1

接着,再次启动 worker,可以发现没有报错了,启动成功!

启动定时任务监听器

在 HttpRunnerManager 的根目录( manage.py 所在的路径),通过以下命令启动定时任务celery

python3 manage.py celery beat --loglevel=info

也可以通过后台执行的方式启动 celery

nohup python3 manage.py celery beat --loglevel=info >celery.log 2>&1 &

启动成功时,显示如下内容:

[root@bogon HttpRunnerManager-master]# python3 manage.py celery beat --loglevel=info
celery beat v3.1.26.post2 (Cipater) is starting.
__    -    ... __   -        _
Configuration ->
    . broker -> amqp://admin:**@192.168.89.128:5672//
    . loader -> celery.loaders.app.AppLoader
    . scheduler -> djcelery.schedulers.DatabaseScheduler

    . logfile -> [stderr]@%INFO
    . maxinterval -> now (0s)

启动任务监控后台

要完成任务监控,需要启动 flower,这个我们在最开始搭建环境时已经安装,是在 requirements.txt 中,如果没有安装的话可以通过 pip3 进行安装。

flower

接下来启动 flower 环境,直接执行命令:flower

也可以通过后台执行的方式启动 flower

nohup flower >flower.log 2>&1 &

如果出现报错:bash: flower: command not found,提示找不到相关命令,那么就需要先设置软链接。首先,查找到 flower 的路径,然后将该路径添加到 /usr/bin/ 下即可,最后执行命令:flower,启动flower时默认的端口是 5555

[root@bogon HttpRunnerManager-master]# flower
bash: flower: command not found
[root@bogon HttpRunnerManager-master]# find / -name flower 
/root/python36/bin/flower
/root/python36/lib/python3.6/site-packages/flower
[root@bogon HttpRunnerManager-master]# ln -s /root/python36/bin/flower /usr/bin/flower
[root@bogon HttpRunnerManager-master]# flower
[I 191229 17:29:58 command:139] Visit me at http://localhost:5555
[I 191229 17:29:58 command:144] Broker: amqp://guest:**@localhost:5672//
[I 191229 17:29:58 command:147] Registered tasks: 
    ['celery.backend_cleanup',
     'celery.chain',
     'celery.chord',
     'celery.chord_unlock',
     'celery.chunks',
     'celery.group',
     'celery.map',
     'celery.starmap']

最后,检查一下 5555 端口是否已开放,在Windows的浏览器下输入地址访问flower管理界面:http://ip地址:5555/

flower Management Interface

异步执行

到这里,我们在模块和项目执行用例时,选择异步执行方式,便不会报错了。

Asynchronous execution

当异步执行完毕后,可以在报告管理中查看报告。

Asynchronous execution of the test report

定时任务

Task is to set the timer under the menu bar in the test plan.

Timing task interface

New regular tasks, related 定时任务crontab语法, not much description here, you can go online to look for learning.

New task

Timing task list

After setting the timing of the task as above, performed once every 5 minutes with regular, then you can go to report the management interface to view reports.

View Report

Monitor mission

Monitoring mission under the system set up, in fact, before the flowermonitoring environment. But the interface corresponding link address may be wrong, we simply need to change it.

The task of monitoring address

Document is to be modified templates/base.html, as follows ( in about base.html line 134, modified according to their actual situation ):

Modify base.html

After modifying the task of monitoring good link address, refresh the page again, the corresponding link will be updated address, we click on the task monitor menu, you can enter the flowertask monitoring interface background.

flower task monitoring and management interface

OK, here, we deploy HttpRunnerManager interface test platform has been completed and has successfully completed the set up for asynchronous execution, scheduled tasks and task monitoring.

Guess you like

Origin www.cnblogs.com/wintest/p/12115880.html