3

When I try to schedule the celery task using eta option, is not processing as expected date time.

Code Snippet:

 process_time_utc = datetime.datetime.fromtimestamp(time.mktime(x.utctimetuple()))
 process_request.apply_async(eta=process_time_utc,kwargs={'description':xxxx})

settings.py code snippet

CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
CELERY_ENABLE_UTC = Flase
CELERY_ALWAYS_EAGER = False
CARROT_BACKEND = 'django'
BROKER_URL = 'amqp://user2:xxx@localhost:xx56//'
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = ()

# ('Your Name', 'your_email@example.com'),

CELERY_IMPORT = 'xxx.app.tasks'
MANAGERS = ADMINS

DATABASES = {'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': '/test_data/test.db',
    'USER': '',
    'PASSWORD': '',
    'HOST': '',
    'PORT': '',
}}



TIME_ZONE = 'UTC'

Here is the celery output log,

[2014-07-07 20:04:08,407: INFO/MainProcess] 
Got task from broker: xx.xxxx.app.tasks.process_request
[08029a2a-fdf0-4b50-b9a9-bdcf05ba71b5] eta:[2014-07-07 20:11:29+00:00]

[2014-07-07 20:04:48,785: INFO/MainProcess] 
Got task from broker: xx.xxxx.app.tasks.process_request
[624c5592-8ed6-4f2c-93df-d48af584a074] eta:[2014-07-07 20:06:29+00:00]

Note: I have followed this tutorial http://celery.readthedocs.org/en/latest/reference/celery.app.task.html

John Moutafis
  • 22,254
  • 11
  • 68
  • 112
Selva
  • 101
  • 2
  • 8

1 Answers1

2

Eta parameter always has a past datetime. Try to add some delay (seconds, minutes, what you need) or use the countdown parameter

xecgr
  • 5,095
  • 3
  • 19
  • 28
  • 1
    eta: Have you tried with local datetime(not utc)?. Otherwise, Has you used the countdown parameter? – xecgr Jul 08 '14 at 05:39
  • Yes friend.I tried with both utc and local time seems its not working. – Selva Jul 08 '14 at 06:00
  • Have you defined the CELERY_ALWAYS_EAGER parameter in your settings? – xecgr Jul 08 '14 at 06:09
  • Yes.I have tried with CELERY_ALWAYS_EAGER=True seems not working. Regarding countdown parameter only allow time format.But my requirement needs to date time format delay. – Selva Jul 08 '14 at 06:53
  • If you define CELERY_ALWAYS_EAGER, it must be False, otherwise it will be execute at the moment http://stackoverflow.com/questions/16498966/django-celery-how-to-start-a-task-with-a-delay-of-n-seconds-countdown-flag – xecgr Jul 08 '14 at 06:59
  • Hi Friend, when i try to run the request with yesterday date on eta option.Its processing the request.If i specify the delay time, it will not processing as expected – Selva Jul 08 '14 at 07:06
  • Hi, Seems now working fine but it accept only UTC time.Thanks for your support! – Selva Jul 09 '14 at 14:04
  • I encountered the same problem. Would you please show me your client code to send task? @Selva – cherish Sep 20 '16 at 09:32
  • @cherish Will you solved this issue in your application? or do you required any help? ETA will accept only the proper UTC time format. – Selva Nov 07 '16 at 13:33
  • 1
    @Selva yes, I soved this issue. You should use utc time other than local time ```time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(time.mktime(time.strptime("2008-09-17 14:04:00", "%Y-%m-%d %H:%M:%S"))))``` see this: http://stackoverflow.com/questions/79797/how-do-i-convert-local-time-to-utc-in-python – cherish Nov 11 '16 at 11:51