execute a code at a particular date and time (aperidic task) in django

205 views
Skip to first unread message

Rini Michael

unread,
Jun 10, 2014, 1:37:46 AM6/10/14
to django...@googlegroups.com
Hi,
i am looking for a way where i can execute a task at a particular date and time, i tried apscheduler for this purpose but i am finding some difficulty while integerating with django. can anyone help me with this
the flow is
user will specify a particular date and time through GUI --> submit --> the task will be executed at the particular date and time the user mentioned
i have tried the following in django (Apscheduler approach)

import time
from datetime import datetime
from apscheduler.scheduler import Scheduler
import os
def func1(self,exec_date):
    from_time = datetime.datetime.strptime("2014-05-29 13:56:59",'%Y-%m-%d %H:%M:%S')
    self.exec_date = datetime.datetime ( from_time.year,from_time.month,from_time.day,from_time.hour,from_time.minute)
    return exec_date
sched = Scheduler()
sched.start()
def my_job(test,exec_date):
    print test
    os.system("python C://Python27/Lib/idlelib/tim.py")
job = sched.add_date_job(my_job,exec_date, ['hello'])


the issue i am facing is the input that the user gives (date n time) is in forms.py ,i have written the code for apscheduler in views.py and i call the function through urls.py but the code doesn't really seem to work,can anyone suggest me how apscheduler works with django or guide me with some links which give information about that

Thanks in advance

Thanks and regards 
Rini

Malcolm Box

unread,
Jun 10, 2014, 7:16:54 AM6/10/14
to django...@googlegroups.com
The canonical answer to this is to use Celery, which provides a task queue for any background/scheduled tasks you want to use.

It's pretty easy to get set up, and works well.

Malcolm

Rini Michael

unread,
Jun 10, 2014, 7:43:32 AM6/10/14
to django...@googlegroups.com
Hi Malcolm
Thanks for your reply,i have been looking into celery as well,but i found that celery is used for periodic task and i am looking to execute aperiodic task.please correct me if i am wrong

Thanks in advance

Javier Guerra Giraldez

unread,
Jun 10, 2014, 9:18:12 AM6/10/14
to django...@googlegroups.com
On Tue, Jun 10, 2014 at 6:43 AM, Rini Michael <rinzy...@gmail.com> wrote:
> Thanks for your reply,i have been looking into celery as well,but i found
> that celery is used for periodic task and i am looking to execute aperiodic
> task.please correct me if i am wrong


check the T.apply_async(eta=<datetimeobject>) option [1]


[1]: http://docs.celeryproject.org/en/latest/userguide/calling.html#id3

--
Javier

Rini Michael

unread,
Jun 11, 2014, 3:40:56 PM6/11/14
to django...@googlegroups.com
Thank you Javier



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFkDaoTVAe9HPXaotJUNL%3DNgFVH5_yEqaLJNbbWhgfhMCTDjhw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages