-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Celery and Redis for periodic tasks
- Loading branch information
Showing
10 changed files
with
162 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .celery import app as celery_app | ||
|
||
__all__ = ('celery_app',) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import os | ||
from celery import Celery | ||
from celery.schedules import crontab | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ecomm1.settings') | ||
|
||
app = Celery('store') | ||
|
||
app.config_from_object('django.conf:settings', namespace='CELERY') | ||
|
||
app.autodiscover_tasks() | ||
|
||
# celery beat tasks | ||
app.conf.beat_schedule = { | ||
'text-every-minute': { | ||
'task': 'store.tasks.make_goods_update', | ||
'schedule': crontab(minute='0', hour='*/1'), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from celery import shared_task, Celery | ||
from threading import Thread | ||
import os | ||
from .update_products import FeedParser, ProductUpdater | ||
|
||
|
||
app = Celery() | ||
|
||
|
||
@shared_task | ||
def make_goods_update(): | ||
feed_url = os.environ.get('GOODS_FEED_URL') | ||
feed_parser = FeedParser(feed_url) | ||
product_updater = ProductUpdater(feed_parser) | ||
Thread(target=product_updater.update_products, args=()).start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters