Schedule 1-time task with scheduler

2 views
Skip to first unread message

Jim Steil

unread,
Apr 24, 2007, 3:48:08 PM4/24/07
to turbo...@googlegroups.com
Has anyone tried to add a task to the TurboGears scheduler and specify
that it should run only once?

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

Diez B. Roggisch

unread,
Apr 25, 2007, 3:18:01 AM4/25/07
to turbo...@googlegroups.com
Jim Steil schrieb:

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

Mark Godfrey

unread,
Apr 25, 2007, 5:00:20 AM4/25/07
to TurboGears
I did this by creating a new Task sub-class called RunOnce, and using
that to

## 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!

Reply all
Reply to author
Forward
0 new messages