-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
112 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from celery.schedules import crontab | ||
|
||
|
||
timezone = 'Europe/Berlin' | ||
|
||
include = ( | ||
'gitmostwanted.tasks.repo_most_starred', 'gitmostwanted.tasks.repo_stars', | ||
'gitmostwanted.tasks.repo_metadata', 'gitmostwanted.tasks.repo_status', | ||
'gitmostwanted.tasks.github' | ||
) | ||
|
||
# celery beat | ||
beat_schedule = { | ||
'metadata-refresh': { | ||
'task': 'gitmostwanted.tasks.repo_metadata.metadata_refresh', | ||
'schedule': crontab(minute=30, hour=0), | ||
'args': [14] | ||
}, | ||
'metadata-erase': { | ||
'task': 'gitmostwanted.tasks.repo_metadata.metadata_erase', | ||
'schedule': crontab(minute=50, hour=0) | ||
}, | ||
'metadata-maturity': { | ||
'task': 'gitmostwanted.tasks.repo_metadata.metadata_maturity', | ||
'schedule': crontab(minute=30, hour=1), | ||
'args': [3] | ||
}, | ||
'metadata-trend': { | ||
'task': 'gitmostwanted.tasks.repo_metadata.metadata_trend', | ||
'schedule': crontab(minute=0, hour=5, day_of_month=1), | ||
'args': [56] | ||
}, | ||
'most-starred-day': { | ||
'task': 'gitmostwanted.tasks.repo_most_starred.most_starred_day', | ||
'schedule': crontab(minute=0, hour=8) | ||
}, | ||
'most-starred-week': { | ||
'task': 'gitmostwanted.tasks.repo_most_starred.most_starred_week', | ||
'schedule': crontab(minute=0, hour=9, day_of_week=0) | ||
}, | ||
'most-starred-month': { | ||
'task': 'gitmostwanted.tasks.repo_most_starred.most_starred_month', | ||
'schedule': crontab(minute=0, hour=10, day_of_month=1) | ||
}, | ||
'status-refresh': { | ||
'task': 'gitmostwanted.tasks.repo_status.status_refresh', | ||
'schedule': crontab(minute=0, hour=3), | ||
'args': [28] | ||
}, | ||
'status-detect': { | ||
'task': 'gitmostwanted.tasks.repo_status.status_detect', | ||
'schedule': crontab(minute=30, hour=4), | ||
'args': [28, 4] | ||
}, | ||
'stars-mature': { | ||
'task': 'gitmostwanted.tasks.repo_stars.stars_mature', | ||
'schedule': crontab(minute=30, hour=3, day_of_week='*/2'), | ||
'args': [28] | ||
} | ||
} |
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,11 @@ | ||
from abc import ABC | ||
|
||
from celery import Task | ||
|
||
from gitmostwanted.app import app | ||
|
||
|
||
class FlaskContextTask(Task, ABC): | ||
def __call__(self, *args, **kwargs): | ||
with app.app_context(): | ||
return super().__call__(*args, **kwargs) |
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
from celery import Celery | ||
|
||
|
||
def instance(app): | ||
""":rtype: Celery""" | ||
return Celery( | ||
app.import_name, | ||
broker=app.config.get('CELERY_URL_BROKER'), | ||
backend=app.config.get('CELERY_URL_BACKEND'), | ||
task_cls='lib.celery.flask_context_task:FlaskContextTask' | ||
) |
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 @@ | ||
pytest_plugins = ["celery.contrib.pytest"] |
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 |
---|---|---|
@@ -1,25 +1,26 @@ | ||
from gitmostwanted.services.celery import instance | ||
from unittest import TestCase, mock | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from gitmostwanted.web import app | ||
|
||
|
||
class ServicesCeleryTestCase(TestCase): | ||
def test_use_flask_context(self): | ||
context = mock.MagicMock() | ||
@pytest.fixture(scope='session') | ||
def celery_parameters(): | ||
return {'task_cls': 'lib.celery.flask_context_task:FlaskContextTask'} | ||
|
||
|
||
app.app_context = lambda: context | ||
app.config['CELERY_ALWAYS_EAGER'] = True | ||
app.config['CELERY_IGNORE_RESULT'] = True | ||
def test_use_flask_context(celery_app, celery_worker): | ||
context = mock.MagicMock() | ||
|
||
cell = instance(app) | ||
app.app_context = lambda: context | ||
|
||
class FakeTask(cell.Task): | ||
name = 'test' | ||
@celery_app.task | ||
def test(): | ||
return 1 | ||
|
||
def run(self): pass | ||
celery_worker.reload() | ||
|
||
task = FakeTask() | ||
cell.tasks.register(task) | ||
task.delay() | ||
test.delay().get(timeout=10) | ||
|
||
context.__enter__.assert_called_once_with() | ||
context.__enter__.assert_called_once_with() |