LAMP:如何实现调度?
我的应用程序的用户需要能够安排某些任务在特定时间运行(例如,仅一次、每分钟、每小时等)。我的计划是让 cron 每分钟运行一个脚本来检查应用程序是否有要执行的任务。如果是,则执行任务。
问题:
- 每分钟运行一次 cron 是一个好主意吗?
- 如何像 cron 那样在数据库间隔中建模(例如每分钟、每小时的第 5 分钟等)?
我正在使用灯。
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:
- Is the running of cron every minute a good idea?
- 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
或者,您知道,不做任何实际工作,只需为用户创建一个界面,然后在 cron 中发布条目!与其让 cron 每分钟调用您一次,不如让它按照用户的指示调用脚本。当他们添加或更改作业时,重写 crontab。
没什么大不了的。
在unix中,cron允许每个用户(即unix登录)拥有自己的crontab,因此您可以拥有一个专用于您的应用程序的crontab,而不必为此使用root crontab。
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.
您的意思是您有一系列用户定义的作业需要以用户定义的时间间隔执行,并且您希望 cron 促进这些作业的处理?如果是这样,您需要一个至少包含 2 个字段的数据库:
工作,
OFTEN
其中 OFTEN 是他们希望作业运行的频率,使用类似于 CRON 的语法。
然后,您需要编写一个脚本(用 python、ruby 或某种类似的语言)来解析该数据。该脚本将通过您的实际 cron 每 1 分钟运行一次。
看看这个StackOverflow问题,以及这个 StackOverflow 问题,关于如何通过 python 解析 crontab 数据。
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.