python - DJANGO Celery on Application Server + Mail server -
i trying configure django + celery on application server separate mail service server.
both servers has same files:
app_name/settings.py
broker_url = "sqs://%s:%s@" % (aws_access_key_id,aws_secret_access_key) celery_timezone = 'america/new_york' celery_accept_content = ['pickle','json', 'msgpack', 'yaml'] celery.schedules import crontab datetime import timedelta celery_routes = { 'mail.tasks.send_reminder_email_end_user': {'queue': 'scheduler'}, 'mail.tasks.send_all_daily_new_user_email': {'queue': 'scheduler'}, 'mail.tasks.send_notification_email': {'queue': 'scheduler'}, 'mail.tasks.send_new_post_daily_email': {'queue': 'scheduler'}, 'insightstat.tasks.save_stats_history_daily': {'queue': 'scheduler'}, } celery_disable_rate_limits = true celerybeat_schedule = { 'send_reminder_email_daily': { 'task': 'mail.tasks.send_reminder_email_end_user', 'schedule': crontab(minute= 0,hour=7) }, 'update_stats_history_daily': { 'task': 'insightstat.tasks.save_stats_history_daily', 'schedule': crontab(minute= 0,hour=1) }, 'send_notification_email_weekly': { 'task': 'mail.tasks.send_notification_email', 'schedule': crontab(minute= 0,hour=8) }, 'send_digest_email_daily': { 'task': 'mail.tasks.send_new_post_daily_email', 'schedule': crontab(minute= 0,hour=8) }, 'send_daily_new_users': { 'task': 'mail.tasks.send_all_daily_new_user_email', 'schedule': crontab(minute= 0,hour=7) }, 'send_digest_email_weekly': { 'task': 'mail.tasks.send_weekly_digest', 'schedule': crontab(minute= 0,hour=8,day_of_week='mon') }, } mail/tasks.py file:
@shared_task(queue='scheduler') def send_all_daily_new_user_email(): apps = application.objects.all() app in apps: daily_new_user_email.delay(app) @shared_task(queue='daily_user') def daily_new_user_email(app): print "sending daily_new_user_email" if not app.digest_email: print "app digest off, return" homecoming if not app.owner.all(): homecoming yesterday = date.today() - timedelta(days=1) users= app.appuser.filter(created_at__gt=yesterday) users_count = users.count() owner = app.owner.all()[0] if users_count == 0: print "no new users %s " % owner.email homecoming recent_user = users[0] subject = "%s new subscribers" % str(users_count) content_html = render_to_string('daily_new_users.html',locals()) email = owner.email print sendemail(notification_email,email,subject,content_html,content_html,'daily_new_users') app_name/celery_task.py file contains:
app = celery('app_name', backend='', broker='"sqs://%s:%s@" % (aws_access_key_id,aws_secret_access_key)', include=['mail.tasks']) if __name__ == '__main__': app.start() # using string here means worker not have # pickle object when using windows. app.config_from_object('django.conf:settings') app.autodiscover_tasks(lambda: settings.installed_apps) where: scheduler que on application server , daily_user que on mail service server. using supervisor start celery workers
this sending mail service multiple times user. doing wrong here?
also, can brief @shared_task?
python django celery django-celery celery-task
No comments:
Post a Comment