Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2474 (closed enhancement: fixed)

Opened 9 years ago

Last modified 8 years ago

Cron-like way of scheduling tasks in TGScheduler

Reported by: bochecha Owned by: vinces1979
Priority: normal Milestone: irrespective
Component: Scheduler Version: trunk
Severity: normal Keywords:
Cc:

Description

Attached is a patch to add a new way of creating a task in the TGScheduler : a cron-like task.

This new Task class takes one parameter different from other Task classes: a string written in cron-like syntax.

This allows to schedule jobs with complex scheduling. For example, one might want to run a job every 15 minutes on business days during the working hours:

def hello():
    print "Hello World!"

cron_str = "*/15 8-12,14-18 * * MON-FRI"

task = add_cron_like_task(hello, cron_str, taskname="hello")

If this patch is accepted, I'll also update the documentation at  http://docs.turbogears.org/TGScheduler

Note: this patch introduces a new dependency on python-dateutil for TGScheduler.

Attachments

crontab.patch Download (12.8 KB) - added by bochecha 9 years ago.
crontab.2.patch Download (13.6 KB) - added by bochecha 9 years ago.
cron-doc.patch Download (2.7 KB) - added by bochecha 8 years ago.
imprved docstring

Change History

comment:1 Changed 9 years ago by Chris Arndt

  • Owner changed from faide to vinces1979

Changed 9 years ago by bochecha

comment:2 Changed 9 years ago by bochecha

I just updated the patch to take into account your latest commits.

comment:3 Changed 9 years ago by bochecha

Any news? Could someone review this patch?

FYI, we just deployed it in production and are pretty happy with it for now. Using a non-patched version of TGScheduler would be a big win of course, and I'll keep updating this patch with fixes we make for issues we would encounter on our setup. :)

comment:4 Changed 9 years ago by Chris Arndt

I forwarded this to the current maintainer and asked him to comment on the patch.

comment:5 Changed 9 years ago by bochecha

Looks like this wasn't the best day to comment on this patch again. :)

I just found an issue in python-dateutil.

Basically, if one of the parameters of the cron string is 0, then scheduler will go in an infinite loop and launch the task again and again and again and...

For example, if one schedules a task at 8:00 every day with the string 0 8 * * *, the issue is triggered.

I guess accepting this patch in TGScheduler will have to wait for the upstream issue to be resolved. :(

comment:6 follow-up: ↓ 7 Changed 9 years ago by vinces1979

OK sorry for the delay in responding, I like the cron style scheduling and I can implement when this bug is fixed or a work around is found.

Please keep us updated, and thanks!

comment:7 in reply to: ↑ 6 ; follow-up: ↓ 8 Changed 9 years ago by bochecha

Replying to vinces1979:

OK sorry for the delay in responding, I like the cron style scheduling and I can implement when this bug is fixed or a work around is found.

I just mailed the  python-dateutil maintainer (I couldn't find any bug tracker) with 2 patches for the issue.

This will need a trivial change to the TGScheduler patch afterwards.

I'll be running with patched dateutil and TGScheduler for now, which will hopefully provide some more testing.

However I'd rather not update the patch here for now, as I'm not sure it is a good idea to have TGScheduler depend on a privately patched version of dateutil.

Please keep us updated, and thanks!

I will.

comment:8 in reply to: ↑ 7 Changed 9 years ago by vinces1979

Replying to bochecha:

Replying to vinces1979:

OK sorry for the delay in responding, I like the cron style scheduling and I can implement when this bug is fixed or a work around is found.

I just mailed the  python-dateutil maintainer (I couldn't find any bug tracker) with 2 patches for the issue.

This will need a trivial change to the TGScheduler patch afterwards.

I'll be running with patched dateutil and TGScheduler for now, which will hopefully provide some more testing.

However I'd rather not update the patch here for now, as I'm not sure it is a good idea to have TGScheduler depend on a privately patched version of dateutil.

Please keep us updated, and thanks!

I will.

Sounds good thanks!

comment:9 follow-up: ↓ 10 Changed 9 years ago by bochecha

My patch was accepted in python-dateutil and Gustavo made a new release.

Attached is an updated version of the cron-like patch, adapted to this new dateutil release and fixing the aforementioned bug.

Changed 9 years ago by bochecha

comment:10 in reply to: ↑ 9 Changed 9 years ago by vinces1979

  • Status changed from new to assigned

Replying to bochecha:

My patch was accepted in python-dateutil and Gustavo made a new release.

Attached is an updated version of the cron-like patch, adapted to this new dateutil release and fixing the aforementioned bug.

Thanks bochecha,

I will run over patch and test myself, and if all goes well I will push out a new release shortly

Vince

comment:11 Changed 9 years ago by bochecha

In case you want to try it out, here's the what I'm planning on adding to  the documentation page:

``add_cron_like_task``
    Pass in ``cron_str`` with a string representing the scheduling in a
	cron-like syntax.

	For example, a task that needs to be executed every 15 minutes on working
	days / hours will be expressed as ``*/15 8-12,14-18 * * 1-5``

	Note:

		* just like with ``Cron``, week starts by a ``0`` on Sunday
		* months and days of week can alternatively be specified by the first 3
		letters of their name, case-insensitively. For example:
			* ``3`` is the same as ``WED``
			* ``1-5`` is the same as ``mon-fri``
		* months and days of week can be specified either by their number or the
		first 3 letters of their name, not both:
		    * ``JAN-12`` will raise an exception

comment:12 follow-up: ↓ 13 Changed 9 years ago by vinces1979

pushed crontab2.patch into trunk, I will setup some extra tests and if everything goes good I will release 1.6 tomorrow

comment:13 in reply to: ↑ 12 Changed 9 years ago by vinces1979

Replying to vinces1979:

pushed crontab2.patch into trunk, I will setup some extra tests and if everything goes good I will release 1.6 tomorrow

patched in r7059

comment:14 Changed 9 years ago by vinces1979

  • Status changed from assigned to closed
  • Resolution set to fixed

All tests ran fine, I pushed out 1.6 to pypi this morning

comment:15 Changed 9 years ago by bochecha

  • Status changed from closed to reopened
  • Resolution fixed deleted

I just realized I could have done a much better job at documenting the usage of the CronLikeTask? class.

Here is a patch providing a nice rst documentation.

It's based on the Linux crontab(5) man page, as they already did a wonderful job at documenting Cron. :)

comment:16 Changed 9 years ago by bochecha

Vince, any news?

Maybe I should have opened a new ticket?

comment:17 Changed 8 years ago by chrisz

  • Milestone changed from __unclassified__ to irrespective

comment:18 Changed 8 years ago by bochecha

Is anybody here?

I submit an updated patch that applies on the current trunk.

Changed 8 years ago by bochecha

imprved docstring

comment:19 Changed 8 years ago by vinces1979

Thanks for the patch I will review and merge into trunk

comment:20 Changed 8 years ago by chrisz

  • Status changed from reopened to closed
  • Resolution set to fixed

Merged in to tgscheduler and tg1.1 in r7124 and r7126.

Note: See TracTickets for help on using tickets.