Update celery

pull/530/head
ibuler 2016-11-11 09:48:47 +08:00
parent c6fc3dfe91
commit 2635217421
6 changed files with 55 additions and 28 deletions

View File

@ -9,3 +9,4 @@ from .utils import write_login_log
@shared_task @shared_task
def write_login_log_async(*args, **kwargs): def write_login_log_async(*args, **kwargs):
write_login_log(*args, **kwargs) write_login_log(*args, **kwargs)

View File

1
apps/celerybeat.pid Normal file
View File

@ -0,0 +1 @@
64256

View File

@ -2,5 +2,5 @@ from __future__ import absolute_import
# This will make sure the app is always imported when # This will make sure the app is always imported when
# Django starts so that shared_task will use this app. # Django starts so that shared_task will use this app.
from .celery import app as celery_app # from .celery import app as celery_app

View File

@ -1,21 +1,20 @@
# ~*~ coding: utf-8 ~*~ # # ~*~ coding: utf-8 ~*~
#
from __future__ import absolute_import, unicode_literals # from __future__ import absolute_import, unicode_literals
# import os
import os #
# from celery import Celery
from celery import Celery #
# # set the default Django settings module for the 'celery' program.
# set the default Django settings module for the 'celery' program. # os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'jumpserver.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'jumpserver.settings') #
# from django.conf import settings
from django.conf import settings #
# app = Celery('jumpserver')
app = Celery('jumpserver') #
# # Using a string here means the worker will not have to
# Using a string here means the worker will not have to # # pickle the object when using Windows.
# pickle the object when using Windows. # app.config_from_object('django.conf:settings')
app.config_from_object('django.conf:settings') #
# app.autodiscover_tasks(lambda: [app_config.split('.')[0] for app_config in settings.INSTALLED_APPS])
app.autodiscover_tasks(lambda: [app_config.split('.')[0] for app_config in settings.INSTALLED_APPS]) #

View File

@ -1,11 +1,29 @@
from __future__ import absolute_import from __future__ import absolute_import
import os
from celery import shared_task from celery import shared_task
from celery.schedules import crontab
from django.core.mail import send_mail from django.core.mail import send_mail
# from django.conf import settings
# from common import celery_app
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'jumpserver.settings')
from django.conf import settings from django.conf import settings
app = Celery('jumpserver')
@shared_task(name='send_mail_async') # Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: [app_config.split('.')[0] for app_config in settings.INSTALLED_APPS])
@app.task
def send_mail_async(*args, **kwargs): def send_mail_async(*args, **kwargs):
""" Using celery to send email async """ Using celery to send email async
@ -28,7 +46,15 @@ def send_mail_async(*args, **kwargs):
send_mail(*args, **kwargs) send_mail(*args, **kwargs)
# def send_mail_async(subject, message, from_mail, recipient_list, fail_silently=False, html_message=None): # @celery_app.task
# if settings.CONFIG.MAIL_SUBJECT_PREFIX: # def test(arg):
# subject += settings.CONFIG.MAIL_SUBJECT_PREFIX # print(arg)
# send_mail(subject, message, from_mail, recipient_list, fail_silently=fail_silently, html_message=html_message)
# celery_app.conf.beat_schedule = {
# 'add-every-30-seconds': {
# 'task': 'common.test',
# 'schedule': crontab(minute='*/1'),
# 'args': ('nihao',)
# }
# }