5 ms·
Ask HN: Are there tools to schedule tasks to execute at specific times?
"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.
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.
What other solutions are out there for time-sensitive scheduling for arbitrarily large numbers of tasks?
- horofox 16y agoI don't find cron anywhere bad for it.
- kranner 16y agoAlso I'd assume cron would be more stable and well-tested than any proprietary solution that could be whipped up in a rush.
- btmorex 16y agoDon't use cron for each individual task. Use cron to start a process that runs through your task queue every x minutes.
- nostrademons 16y agoAlmost 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.
- philwelch 16y agoApple 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 http://en.wikipedia.org/wiki/Launchd
- andrewtj 16y agoI don't see how launchd provides any improvement over cron for this task — what am I missing?
- jacksoncarter 16y agoFrom 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 16y agoIf 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?
- mkramlich 16y agoThis 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 16y agoWhile 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...
- s2r2 16y agohttp://adam.heroku.com/past/2010/6/30/replace_cron_with_clockwork/ http://adam.heroku.com/past/2010/6/30/replace_cron_with_cloc... found this here yesterday -- might be near your needs
- jcapote 16y agoI wrote a "framework" to handle this exact problem: http://github.com/capotej/theman 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.
- MichaelApproved 16y agoPHP 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.
- deleted 16y ago[deleted]
- asnyder 16y agoThe 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.
- MrMatt 16y agoLooks like you need something like Delayed Job: http://github.com/tobi/delayed_job http://github.com/tobi/delayed_job Not sure of an equivalent in PHP.