Skip to content

Commit

Permalink
add support for celery v5
Browse files Browse the repository at this point in the history
  • Loading branch information
sontek committed Feb 24, 2021
1 parent 549081a commit a403920
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
8 changes: 3 additions & 5 deletions examples/long_running_with_tm/long_running_with_tm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
Column,
Integer,
Text,
)
)

from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy.orm import (
scoped_session,
sessionmaker,
)
)

from zope.sqlalchemy import ZopeTransactionExtension

DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
DBSession = scoped_session(sessionmaker())
Base = declarative_base()

class TaskItem(Base):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def delete_task(self, task_pk):
@app.task
def add_task(task):
time.sleep(random.choice([2, 4, 6, 8, 10]))
print 'creating task %s' % task
print('creating task %s' % task)
task = TaskItem(task=task)
DBSession.add(task)
transaction.commit()
22 changes: 21 additions & 1 deletion pyramid_celery/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from celery import Celery
from celery import signals
from celery import VERSION as celery_version

from pyramid.paster import bootstrap, setup_logging
from pyramid_celery.loaders import INILoader
Expand All @@ -18,7 +19,26 @@ def add_preload_arguments(parser):


celery_app = Celery()
celery_app.user_options['preload'].add(add_preload_arguments)
if celery_version.major >= 5:
# Celery uses click in v5+
from click import Option
celery_app.user_options['preload'].add(
Option(
('--ini', '-i',),
help='Paste ini configuration file.'
)
)
celery_app.user_options['preload'].add(
Option(
('--ini-var',),
help='Comma separated list of key=value to pass to ini.'
)
)

else:
celery_app.user_options['preload'].add(
add_preload_arguments
)

ini_file = None

Expand Down

0 comments on commit a403920

Please sign in to comment.