

Ask HN: Are there tools to schedule tasks to execute at specific times? - kanzure

"cron" and "at" seem like too much of a (bad) hack for anything more than a couple thousand tasks that need to be scheduled. I am writing a web app that has to close auctions and send out emails, transfer money/tokens around, etc.<p>The PHP programmers tell me to just do a lazy check on each page load for auctions that are closed- if I do that, I'd probably throw it on to an SQS queue and have some server instance processing the closing auctions in bulk. But what if it's a cold day in hell and nobody is triggering these page loads? etc.<p>What other solutions are out there for time-sensitive scheduling for arbitrarily large numbers of tasks?
======
btmorex
Don't use cron for each individual task. Use cron to start a process that runs
through your task queue every x minutes.

------
mkramlich
This kind of Ask HN is waaaay better suited for a site like Stack Overflow,
imo. I for one don't want to see HN turn into a site "overflowing" with
common/basic programming design questions every day. No ill will to the author
of this question, of course, just speaking up.

------
ryanwaggoner
While it's cool that you're getting the help you need, I wonder if something
like StackOverflow isn't a better place for these kinds of specific technical
implementation questions? Just a thought...

------
jacksoncarter
From what you've described, it's not really a thousand tasks, it's one task:
close out auctions. What the PHP programmers suggest is a horrible idea. For
two reasons, first, the reason you describe: nobody loading the page, and
second because it may close out auctions way more often than necessary.
Imagine if you get 1,000 people a second calling the close out auctions task.

So if it really is just one close out auctions task, why not build a cron job
to find all the closed auctions and do what you gotta do in a loop?

~~~
millettjon
If it is just one task, why do you even need cron? Just use a simple daemon
process that sleeps for a bit and then checks for work?

------
nostrademons
Almost everyone I know just uses cron or various proprietary replacements for
cron that work basically the same way. If you want to go the proprietary way,
you write a persistent daemon server that keeps a priority queue of tasks to
execute, wakes up and executes the next one on the heap, figures out what time
it is, and then sleeps until the next task is due. If it receives
notifications of new tasks, it wakes up, adds them to the heap, and then
recomputes the amount of time it must sleep.

------
jcapote
I wrote a "framework" to handle this exact problem:
<http://github.com/capotej/theman>

It's a simple wrapper over rufus-scheduler and god to create scheduled workers
that execute tasks at specific times.

------
asnyder
_The PHP programmers tell me to just do a lazy check on each page load for
auctions that are closed_

I don't know if I believe this blanket statement. I personally can't imagine a
competent PHP programmer, let alone any programmer suggesting this route.
While it may be in vogue to bash PHP programmers, it's doubtful that asking
this question in #php would produce such a result.

As a matter of fact, you could've just as easily said "The Ruby programmers",
or "The Python programmers", since I'm sure there exists a group of
programmers using those languages that may think that suggestion is a good
idea. Grouping an entire set of programmers into your question is in poor
taste.

This is my opinion, as a very competent PHP programmer.

------
philwelch
Apple has a program called launchd that's used in Mac OS X to replace cron and
friends. It's Apache licensed: <http://en.wikipedia.org/wiki/Launchd>

~~~
andrewtj
I don't see how launchd provides any improvement over cron for this task —
what am I missing?

------
MrMatt
Looks like you need something like Delayed Job:

<http://github.com/tobi/delayed_job>

Not sure of an equivalent in PHP.

------
horofox
I don't find cron anywhere bad for it.

~~~
kranner
Also I'd assume cron would be more stable and well-tested than any proprietary
solution that could be whipped up in a rush.

------
MichaelApproved
PHP page load hack is a solution if you're writing a web app for end users
that doesn't have access to cron jobs.

If you control the server then the better solution would be to schedule one
job that runs every minute or so and executes the task you need.

------
s2r2
[http://adam.heroku.com/past/2010/6/30/replace_cron_with_cloc...](http://adam.heroku.com/past/2010/6/30/replace_cron_with_clockwork/)

found this here yesterday -- might be near your needs

