launching cron job programmatically

launching cron job programmatically

Posted by: FreemanNg
Posted on: 2009-10-04 15:48:00

Is there a way to programmatically launch a cron job script in a way that still uses the locking feature, so that it won't interfere with any scheduled run of the script that might already be executing and vice versa? (The situation is that I have a cron job that I'd occasionally like to force a run of in response to some user action on my site.) A Ruby specific answer would be nice, but not necessary. Thanks.

Re: launching cron job programmatically

Posted by: andrewf
Posted on: 2009-10-05 10:16:00

Cron job locking internally just works by creating a cronjob that looks like this:

/usr/local/bin/setlock -n /tmp/cronlock.UNIQUEID COMMAND

where UNIQUEID is a unique identifier for the job, and COMMAND is the original command.

Re: launching cron job programmatically

Posted by: FreemanNg
Posted on: 2009-10-05 12:27:00

Thanks.

I assume that the unique ID must be unique to the command and not to the run of the command. (i.e. every time I launch the same command, it should get the same ID, because that's what the locking is based on.) If that's the case, how do I find out what ID cron itself is using for a given job? (In order to prevent collisions between scheduled runs of the command and my manual invocations of it.)

Re: launching cron job programmatically

Posted by: Atropos7
Posted on: 2009-10-05 12:55:00

In reply to:

If that's the case, how do I find out what ID cron itself is using for a given job? (In order to prevent collisions between scheduled runs of the command and my manual invocations of it.)


Well after you setup the cron job in the web panel, login to shell and then use the crontab program of course.




Customer since 2000 cool openvein.org

Re: launching cron job programmatically

Posted by: FreemanNg
Posted on: 2009-10-05 13:00:00

Thanks. One more question: once I create a cron job through the Dreamhost panel, will its unique ID never change? Or might it change if I edit the job or something like that?

Re: launching cron job programmatically

Posted by: Atropos7
Posted on: 2009-10-05 13:04:00

In reply to:

Thanks. One more question: once I create a cron job through the Dreamhost panel, will its unique ID never change? Or might it change if I edit the job or something like that?


I dunno! It will probably will change if you edit it.



Customer since 2000 cool openvein.org

Re: launching cron job programmatically

Posted by: FreemanNg
Posted on: 2009-10-05 13:07:00

Thanks, to both of you. I'm continually amazed by how quickly the help comes, both here and directly from support. Dreamhost is, like, a *dream host*.

Re: launching cron job programmatically

Posted by: andrewf
Posted on: 2009-10-05 13:16:00

> Thanks. One more question: once I create a cron job through the Dreamhost panel, will its unique ID never change? Or might it change if I edit the job or something like that?

The unique ID should remain constant as long as you don't delete and recreate the job.

Tags: necessary thanksrubycron job