I've looked at the doc and a bit at the code and it appears as though
this won't work. The doc says there are three methods used to schedule
a task:
1. add_interval_task
2. add_weekday_task
3. add_monthday_task
I took a look at the scheduler code and it appears as though there is
another option, add_one_time_task (which sets the interval to 0), but
that calls add_interval_task which will reject the task if the interval
is set to 0. Does anyone know any history on this and whether or not
you can schedule a task to run just once?
The reason I want to do this is because I want my user to be able to
initiate a job that will then run in a separate thread and give control
back to the user right away. I'm writing a page that will allow them to
generate invoices and want the job to run in the background and will
then signal them via email when it is complete.
Or, am I going about this all wrong? If so, where might you suggest I
look for the answer?
-Jim
Why don't you just spawn that thread? Where is the gain of scheduling it?
It's another question if the scheduler should support this - but for
your use-case, I don't see any reason to use it anyway.
Diez
## This class lets us just run a task once via
Scheduler.schedule_task()
class RunOnceTask(scheduler.Task):
def reschedule(self, scheduler):
# We don't reschedule!
pass
then we do something like:
task = RunOnceTask(task_name, task_func, arg_list, keywords)
scheduler._scheduler_instance.schedule_task(task, 0)
hope this helps!