Skip to content

Commit

Permalink
Merge pull request #1 from sharingcloud/celery4
Browse files Browse the repository at this point in the history
[SC] Celery 4 support
  • Loading branch information
Srynetix authored Oct 13, 2020
2 parents a78b3a5 + 189da69 commit 6d57ddf
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 24 deletions.
2 changes: 1 addition & 1 deletion djcelery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
import sys

VERSION = (3, 3, 0)
VERSION = (4, 0, 0, 'sc')
__version__ = '.'.join(map(str, VERSION[0:3])) + ''.join(VERSION[3:])
__author__ = 'Ask Solem'
__contact__ = '[email protected]'
Expand Down
16 changes: 11 additions & 5 deletions djcelery/management/commands/celery.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import, unicode_literals

from celery import VERSION as CELERY_VERSION
from celery.bin import celery

from djcelery.app import app
Expand All @@ -11,11 +12,16 @@
class Command(CeleryCommand):
"""The celery command."""
help = 'celery commands, see celery help'
options = (
tuple(CeleryCommand.options) +
tuple(base.get_options() or ()) +
tuple(getattr(base, 'preload_options', ()))
)
if CELERY_VERSION[0] < 4:
options = (
tuple(CeleryCommand.options) +
tuple(base.get_options() or ()) +
tuple(getattr(base, 'preload_options', ()))
)
else:
def add_arguments(self, parser):
super().add_arguments(parser)
base.add_arguments(parser)

def run_from_argv(self, argv):
argv = self.handle_default_options(argv)
Expand Down
19 changes: 14 additions & 5 deletions djcelery/management/commands/celerybeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
from __future__ import absolute_import, unicode_literals

from celery import VERSION as CELERY_VERSION
from celery.bin import beat

from djcelery.app import app
Expand All @@ -16,11 +17,19 @@
class Command(CeleryCommand):
"""Run the celery periodic task scheduler."""
help = 'Old alias to the "celery beat" command.'
options = (
tuple(CeleryCommand.options) +
tuple(beat.get_options()) +
tuple(getattr(beat, 'preload_options', ()))
)
if CELERY_VERSION[0] < 4:
options = (
tuple(CeleryCommand.options) +
tuple(beat.get_options()) +
tuple(getattr(beat, 'preload_options', ()))
)
else:
def add_arguments(self, parser):
super().add_arguments(parser)
beat.add_arguments(parser)

# Deprecated args
parser.add_argument("--workdir", help="deprecated")

def handle(self, *args, **options):
beat.run(*args, **options)
22 changes: 16 additions & 6 deletions djcelery/management/commands/celerycam.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
from __future__ import absolute_import, unicode_literals

from celery import VERSION as CELERY_VERSION
from celery.bin import events

from djcelery.app import app
Expand All @@ -16,13 +17,22 @@
class Command(CeleryCommand):
"""Run the celery curses event viewer."""
help = 'Takes snapshots of the clusters state to the database.'
options = (
tuple(CeleryCommand.options) +
tuple(ev.get_options()) +
tuple(getattr(ev, 'preload_options', ()))
)
if CELERY_VERSION[0] < 4:
options = (
tuple(CeleryCommand.options) +
tuple(ev.get_options()) +
tuple(getattr(ev, 'preload_options', ()))
)
else:
def add_arguments(self, parser):
super().add_arguments(parser)
ev.add_arguments(parser)

# Deprecated args
parser.add_argument("--workdir", help="deprecated")

def handle(self, *args, **options):
"""Handle the management command."""
options['camera'] = 'djcelery.snapshot.Camera'
if not options["camera"]:
options['camera'] = 'djcelery.snapshot.Camera'
ev.run(*args, **options)
16 changes: 11 additions & 5 deletions djcelery/management/commands/celeryd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
from __future__ import absolute_import, unicode_literals

from celery import VERSION as CELERY_VERSION
from celery.bin import worker

from djcelery.app import app
Expand All @@ -16,11 +17,16 @@
class Command(CeleryCommand):
"""Run the celery daemon."""
help = 'Old alias to the "celery worker" command.'
options = (
tuple(CeleryCommand.options) +
tuple(worker.get_options()) +
tuple(getattr(worker, 'preload_options', ()))
)
if CELERY_VERSION[0] < 4:
options = (
tuple(CeleryCommand.options) +
tuple(worker.get_options()) +
tuple(getattr(worker, 'preload_options', ()))
)
else:
def add_arguments(self, parser):
super().add_arguments(parser)
worker.add_arguments(parser)

def handle(self, *args, **options):
worker.check_args(args)
Expand Down
10 changes: 9 additions & 1 deletion djcelery/management/commands/celeryd_detach.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import sys

from celery import VERSION as CELERY_VERSION
from celery.bin import celeryd_detach

from djcelery.management.base import CeleryCommand
Expand All @@ -16,10 +17,17 @@
class Command(CeleryCommand):
"""Run the celery daemon."""
help = 'Runs a detached Celery worker node.'
options = celeryd_detach.OPTION_LIST
if CELERY_VERSION[0] < 4:
options = celeryd_detach.OPTION_LIST
else:
def add_arguments(self, parser):
celeryd_detach.add_arguments(parser)

def run_from_argv(self, argv):

class detached(celeryd_detach.detached_celeryd):
execv_argv = [os.path.abspath(sys.argv[0]), 'celery', 'worker']

if CELERY_VERSION[0] >= 4:
argv.remove("celeryd_detach")
detached().execute_from_commandline(argv)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def extra_args(self):
package_data=package_data,
zip_safe=False,
install_requires=[
'celery>=3.1.15,<4.0',
'celery>=3.1.15',
'django>=1.8',
],
cmdclass={'test': RunTests,
Expand Down

0 comments on commit 6d57ddf

Please sign in to comment.