diff --git a/README.md b/README.md index 29ac949..d701771 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ python manage.py createsuperuser python manage.py runserver 0.0.0.0:80 ``` -* 扩展功能 +* 扩展功能-异步1 推荐 定时任务用celery ```bash #需要安装redis #启动celery异步任务 @@ -56,6 +56,14 @@ cd seal celery -B -A seal worker -l info ``` +* 扩展功能-异步2 普通异步任务 用 dramatiq +```bash +cd system/decorator/asynchronous/ +dramatiq asynchronous --watch . --log-file /tmp/dramatiq.log + +``` + + ## 注意 * 如果想直接拿来做生产项目,请重新生成一个 settings 文件里面的 SECRET_KEY * 时区问题 diff --git a/requirements.txt b/requirements.txt index 5f16a27..06228ac 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ amqp==2.4.2 +argh==0.26.2 backcall==0.1.0 billiard==3.5.0.5 celery==4.2.1 @@ -9,23 +10,31 @@ Django==2.1.7 django-bootstrap4==0.0.7 django-celery-beat==1.4.0 django-celery-results==1.0.4 +django-crispy-forms==1.7.2 django-pure-pagination==0.3.0 django-timezone-field==3.0 +dramatiq==1.5.0 +gevent==1.4.0 +greenlet==0.4.15 idna==2.8 ipython==6.4.0 ipython-genutils==0.2.0 jedi==0.12.0 +jsonfield==2.0.2 kombu==4.4.0 mysqlclient==1.4.2.post1 parso==0.2.1 +pathtools==0.1.2 pexpect==4.6.0 pickleshare==0.7.4 +prometheus-client==0.2.0 prompt-toolkit==1.0.15 ptyprocess==0.5.2 Pygments==2.2.0 python-crontab==2.3.6 python-dateutil==2.8.0 pytz==2018.4 +PyYAML==5.1 redis==3.2.0 requests==2.21.0 simplegeneric==0.8.1 @@ -33,4 +42,6 @@ six==1.11.0 traitlets==4.3.2 urllib3==1.24.1 vine==1.2.0 -wcwidth==0.1.7 \ No newline at end of file +watchdog==0.8.3 +watchdog-gevent==0.1.0 +wcwidth==0.1.7 diff --git a/system/decorator/asynchronous/__init__.py b/system/decorator/asynchronous/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/system/decorator/asynchronous/asynchronous.py b/system/decorator/asynchronous/asynchronous.py new file mode 100644 index 0000000..41501bb --- /dev/null +++ b/system/decorator/asynchronous/asynchronous.py @@ -0,0 +1,12 @@ +import dramatiq +import requests +from dramatiq.brokers.redis import RedisBroker + +redis_broker = RedisBroker(host="127.0.0.1", port=6379) +dramatiq.set_broker(redis_broker) + +@dramatiq.actor +def count_words(url): + print(url) + +count_words.send("http://example.com") \ No newline at end of file