Skip to content

Instantly share code, notes, and snippets.

@rightx2
Created May 2, 2017 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rightx2/292fe8443cbe0f8ac04909c7d2452ab1 to your computer and use it in GitHub Desktop.
Save rightx2/292fe8443cbe0f8ac04909c7d2452ab1 to your computer and use it in GitHub Desktop.
# .
# .
# ├── myapp
# │ ├── __init__.py
# │ ├── admin.py
# │ ├── migrations
# │ ├── models.py
# │ ├── tasks
# │ │ ├── __init__.py ## ==> code
# │ │ └── my_task.py ## ==> code
# │ ├── templates
# │ ├── urls.py
# │ └── views
# ├── config
# │ ├── __init__.py ## ==> code
# │ ├── celery.py ## ==> code
# │ ├── settings
# │ │ ├── __init__.py
# │ │ ├── partials
# │ │ │ ├── __init__.py
# │ │ │ ├── base.py
# │ ├── urls.py
# │ └── wsgi.py
# ├── manage.py
# .
# .
#
# config/celery.py
#
from __future__ import absolute_import, unicode_literals
import os
from celery.schedules import crontab
from celery import Celery
app = Celery('chois_crawler') # session을 여는거구나...
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
app.conf.beat_schedule = {
'task_name': {
'task': 'tasks.my_task',
'schedule': crontab(minute='*/1'),
},
}
#
# config/__init__.py
#
from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app
__all__ = ['celery_app']
#
# myapp/tasks/my_task.py
#
from __future__ import absolute_import, unicode_literals
from celery import shared_task
@shared_task
def crawl_clien_task():
print("hi")
#
# clien/tasks/__init__.py
#
from .my_task import *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment