Created
September 20, 2017 16:26
-
-
Save geoffreybauduin/b3d5606ee5167b137097c9917880e21a to your computer and use it in GitHub Desktop.
Celery eager/non eager mode arguments differences
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
(venv)$ python eager.py | |
WARNING:root:<type 'datetime.datetime'> | |
ERROR:celery.app.trace:Task faulty_task[72907c31-5d49-4989-b630-7ffd1dae88b2] raised unexpected: AssertionError() | |
Traceback (most recent call last): | |
File "/home/gbauduin/tmp/test_celery/venv/local/lib/python2.7/site-packages/celery/app/trace.py", line 374, in trace_task | |
R = retval = fun(*args, **kwargs) | |
File "main.py", line 14, in faulty_task | |
assert not isinstance(date, datetime.datetime) | |
AssertionError |
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
from celery import Celery | |
import datetime | |
import logging | |
cel = Celery() | |
cel.conf.update( | |
task_always_eager=True, | |
) | |
@cel.task(bind=True, name="faulty_task") | |
def faulty_task(self, date): | |
logging.warn(type(date)) | |
assert not isinstance(date, datetime.datetime) | |
if __name__ == "__main__": | |
faulty_task.apply_async(kwargs={ | |
'date': datetime.datetime.now(), | |
}) |
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
[2017-09-20 16:22:44,925: INFO/MainProcess] Received task: faulty_task[13c2b5a2-5bad-4ffe-b977-ba7f163199f2] | |
[2017-09-20 16:22:44,925: DEBUG/MainProcess] TaskPool: Apply <function _fast_trace_task at 0x7fa01813ac80> (args:(u'faulty_task', u'13c2b5a2-5bad-4ffe-b977-ba7f163199f2', {u'origin': u'gen21@8f521076f3f0', u'lang': u'py', u'task': u'faulty_task', u'group': None, u'root_id': u'13c2b5a2-5bad-4ffe-b977-ba7f163199f2', u'delivery_info': {u'priority': 0, u'redelivered': None, u'routing_key': u'celery', u'exchange': u''}, u'expires': None, u'correlation_id': u'13c2b5a2-5bad-4ffe-b977-ba7f163199f2', u'retries': 0, u'timelimit': [None, None], u'argsrepr': u'()', u'eta': None, u'parent_id': None, u'reply_to': u'1286fbcf-deac-3dfb-a747-666542bba2c5', u'id': u'13c2b5a2-5bad-4ffe-b977-ba7f163199f2', u'kwargsrepr': u"{'date': datetime.datetime(2017, 9, 20, 16, 22, 44, 879409)}"}, '[[], {"date": "2017-09-20T16:22:44.879409"}, {"chord": null, "callbacks": null, "errbacks": null, "chain": null}]', u'application/json', u'utf-8') kwargs:{}) | |
[2017-09-20 16:22:44,927: DEBUG/MainProcess] Task accepted: faulty_task[13c2b5a2-5bad-4ffe-b977-ba7f163199f2] pid:13 | |
[2017-09-20 16:22:44,927: WARNING/ForkPoolWorker-2] <type 'unicode'> | |
[2017-09-20 16:22:44,934: INFO/ForkPoolWorker-2] Task faulty_task[13c2b5a2-5bad-4ffe-b977-ba7f163199f2] succeeded in 0.00705210119486s: 'This is ok' |
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
from celery import Celery | |
import logging | |
import json | |
import datetime | |
cel = Celery( | |
"test", broker="redis://127.0.0.1:6379/0", backend="redis://127.0.0.1:6379/0", | |
) | |
@cel.task(bind=True, name="faulty_task") | |
def faulty_task(self, date): | |
logging.warn(type(date)) | |
assert not isinstance(date, datetime.datetime) | |
return "This is ok" | |
if __name__ == "__main__": | |
faulty_task.apply_async(kwargs={ | |
'date': datetime.datetime.now(), | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment