Skip to content

Commit

Permalink
[fix] fix error on task initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Lyisenkov committed Sep 25, 2018
1 parent fbb229e commit 1613f17
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
11 changes: 2 additions & 9 deletions static_sitemaps/conf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
from django.conf import settings

try:
from celery.schedules import crontab
except ImportError:
crontab = None


# Base sitemap config dict as stated in Django docs.
ROOT_SITEMAP = settings.STATICSITEMAPS_ROOT_SITEMAP

Expand Down Expand Up @@ -43,11 +37,10 @@
STORAGE_CLASS = getattr(settings, 'STATICSITEMAPS_STORAGE', 'django.core.files.storage.FileSystemStorage')

# How often should the celery task be run.
CELERY_TASK_REPETITION = getattr(settings, 'STATICSITEMAPS_REFRESH_AFTER', 60)
CELERY_TASK_REPETITION = getattr(settings, 'STATICSITEMAPS_REFRESH_AFTER', None)

# When should the celery task be run.
CELERY_TASK_SCHEDULE = getattr(
settings, 'STATICSITEMAPS_REFRESH_ON', crontab(hour=0, minute=0) if crontab else None)
CELERY_TASK_SCHEDULE = getattr(settings, 'STATICSITEMAPS_REFRESH_ON', None)

# URL to serve sitemaps from.
_url = getattr(settings, 'STATICSITEMAPS_URL', None)
Expand Down
8 changes: 4 additions & 4 deletions static_sitemaps/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def __init__(self):
if conf.CELERY_TASK_REPETITION and conf.CELERY_TASK_SCHEDULE:
raise ValueError(
'You should set one setting of STATICSITEMAPS_REFRESH_AFTER or STATICSITEMAPS_REFRESH_ON')
if conf.CELERY_TASK_REPETITION:
self.run_every = timedelta(minutes=conf.CELERY_TASK_REPETITION)
super().__init__()
else:
if conf.CELERY_TASK_SCHEDULE:
self.run_every = conf.CELERY_TASK_SCHEDULE
else:
self.run_every = timedelta(minutes=(conf.CELERY_TASK_REPETITION or 60))
super().__init__()

def run(self, **kwargs):
generate_sitemap(verbosity=1)

0 comments on commit 1613f17

Please sign in to comment.