parent
c2d11a6d94
commit
6a43412406
9 changed files with 65 additions and 7 deletions
@ -1 +1,4 @@ |
|||||||
py .\manage.py runserver 0.0.0.0:8000 |
py .\manage.py runserver 0.0.0.0:8000 |
||||||
|
celery -A dingxin_toolbox_drf worker -l info -P solo # windows |
||||||
|
celery -A dingxin_toolbox_drf worker -l info # linux |
||||||
|
celery -A dingxin_toolbox_drf beat -l info |
||||||
@ -1,2 +1,6 @@ |
|||||||
import pymysql |
import pymysql |
||||||
pymysql.install_as_MySQLdb() |
from .celery import app as celery_app |
||||||
|
|
||||||
|
pymysql.install_as_MySQLdb() |
||||||
|
|
||||||
|
__all__ = ('celery_app',) |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
import os |
||||||
|
from celery import Celery |
||||||
|
from celery.schedules import crontab |
||||||
|
from django.conf import settings |
||||||
|
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dingxin_toolbox_drf.settings') |
||||||
|
|
||||||
|
# 创建 Celery实例 |
||||||
|
app = Celery('dingxin_toolbox_drf') |
||||||
|
|
||||||
|
# 加载配置文件中的Celery配置 |
||||||
|
app.config_from_object('django.conf:settings', namespace='CELERY') |
||||||
|
|
||||||
|
# 自动发现并添加任务 |
||||||
|
app.autodiscover_tasks() |
||||||
|
|
||||||
|
# app.conf.beat_schedule = { |
||||||
|
# 'update_client_task': { |
||||||
|
# 'task': 'update.tasks.update_client', |
||||||
|
# # 'schedule': crontab(hour='*'), |
||||||
|
# 'schedule': 30, |
||||||
|
# }, |
||||||
|
# } |
||||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,13 @@ |
|||||||
|
from celery import shared_task |
||||||
|
import datetime |
||||||
|
from update.utils.client_util_custom import ClientUtilCustom |
||||||
|
|
||||||
|
|
||||||
|
@shared_task |
||||||
|
def update_client(): |
||||||
|
ClientUtilCustom().sync_client_db() |
||||||
|
# with open(r'D:\Code\Work\Python\dingxin_toolbox_drf\update\tasks.txt', 'w', encoding='utf-8') as f: |
||||||
|
# f.write(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) |
||||||
|
# f.close() |
||||||
|
print("task success") |
||||||
|
return True |
||||||
Loading…
Reference in new issue