Hi, There's no need for this - the Task Queue has an ETA argument, which allows you to specify when you want the task to run (as opposed to countdown, which is relative to the current time).
-Nick Johnson On Sun, Feb 7, 2010 at 5:21 PM, Eli Jones <[email protected]> wrote: > I have a task that I need to run at every 5 minute mark.. starting at 9:30 > AM and then running at 9:35, 9:40, ... etc.. > > I used to just have it run.. and then do taskqueue.add() with a > countdown=300 to just run again in 5 minutes. > > As you noticed with your cron.. the drift begins to add up.. and the > task/cron no longer runs at the exact time you want. > > There are two ways I can think of to defeat the "drift" using Taskqueue: > > Both of these methods use chained Tasks.. so.. Task 1 runs.. then it > schedules Task 2 to run.. and Task 2 schedules Task 3 etc.. > > Method 1 (what I'm using): > > The delay (countdown) for the next Taskqueue.add() is set like so - > > now = datetime.today() > seconds = 60*(now.minute) + now.second > delay = 3600 - seconds%3600 > > Doing seconds mod 3600 gives you how many seconds past the last hour we > are.. so.. you just subtract that from the number of seconds in an hour and > that gives you how many seconds there are until the next hour mark. > > Method 2 (lazy method but should work): > > At the beginning of your task.. have it go ahead and add the next hourly > scheduled task. (instead of waiting until the end). This could still give > drift since.. what if something happens to delay the starting of the task? > But, I guess that would be an infrequent issue. > > Have caution, chaining taskqueue tasks together requires you to use a > "name" for each task.. (to prevent an error from branching off two task > chains). > > Also, when you do taskqueue.add().. make sure to do try: except: and handle > these errors quietly - > > taskqueue.TaskAlreadyExistsError, taskqueue.TombstonedTaskError > > And, eventually you will come across the taskqueue.TransientError... have > it retry the .add() process when you get that one. > > > > On Sun, Feb 7, 2010 at 6:09 AM, gwstuff <[email protected]> wrote: > >> Hello, >> >> I have a cron job that runs every hour. It is specified to run 'Every >> 1 hours.' The idea is to generate time series logs that can be >> analyzed later. Unfortunately, every now and then the execution is >> offset by a second, since the time of execution is 1 hour following >> the termination not start of the last run and these offsets add up >> with time. >> >> Is it possible to make it run at exactly 5 minutes past every hour as >> opposed to the 1 hour interval since last termination? I tried a comma- >> separated hourspec - e.g. 00:05,1:05,2:05... but it appears that >> hourspec does not support lists. >> >> Thanks in advance, >> S >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Google App Engine" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<google-appengine%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/google-appengine?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Google App Engine" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-appengine%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-appengine?hl=en. > -- Nick Johnson, Developer Programs Engineer, App Engine Google Ireland Ltd. :: Registered in Dublin, Ireland, Registration Number: 368047 -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
