StackOverflowNewbie
StackOverflowNewbie

Reputation: 40653

LAMP: How to Implement Scheduling?

Users of my application need to be able to schedule certain task to run at certain times (e.g. once only, every every minute, every hour, etc.). My plan is to have a cron run a script every minute to check the application to see if it has tasks to execute. If so, then execute the tasks.

Questions:

  1. Is the running of cron every minute a good idea?
  2. How do I model in the database intervals like cron does (e.g. every minute, ever 5th minute of every hour, etc.)?

I'm using LAMP.

Upvotes: 2

Views: 300

Answers (2)

Will Hartung
Will Hartung

Reputation: 118694

Or, rather than doing any, you know, real work, simply create an interface for the users, and then publish entries in cron! Rather than having cron call you every minute, have it call scripts as directed by the users. When they add or change jobs, rewrite the crontab.

No big deal.

In unix, cron allows each user (unix login that is) to have their own crontab, so you can have one dedicated to your app, don't have to use the root crontab for this.

Upvotes: 1

Patrick Perini
Patrick Perini

Reputation: 22633

Do you mean that you have a series of user-defined jobs that need executed in user-defined intervals, and you'd like to have cron facilitate the processing of those jobs? If so, you'd want to have a database with at least 2 fields: JOB, OFTEN

where OFTEN is how often they'd like the job to run, using syntax similar to CRON.

you'd then need to write a script (in python, ruby, or some similar language) to parse that data. this script would be what runs every 1 minute via your actual cron.

take a look at this StackOverflow question, and this StackOverflow question, regarding how to parse crontab data via python.

Upvotes: 0

Related Questions