在 Gearman 中安排特定日期和时间的作业
据我所知,Gearman 不支持预定作业或延迟作业。我在想,也许预定的作业可以先在 at
中排队,然后在 at
时间段到期后添加到 Gearman 队列中。
at
任务是持久性的,因为它们作为文件写入服务器的 spool 目录中的目录。因此,唯一的瓶颈可能是一个将任务添加到 Gearman 队列的简单脚本,因为 at
无法跨服务器分发。将其传递给 Gearman 来处理实际工作意味着我可以获得适当的工作日志记录等。
这是解决此问题的最佳方法吗?您有其他想法吗?
我选择 Gearman 而不是其他队列解决方案的原因是它有 PHP 扩展。
我正在编写的代码用于维护需要发送的电子邮件队列。因此,我可以指定要发送电子邮件至 [电子邮件受保护]例如,周五 9.50。
From what I can see Gearman does not support scheduled jobs or delayed jobs. I was thinking that perhaps the scheduled job could be queued in at
first and then added to the Gearman queue after the at
time period has expired.
at
tasks are persistent as they are written as files to a directory in the spool directory of the server. So the only bottle neck would potentially be a simple script to add the task to the Gearman queue because at
can't be distributed across servers. Passing it to Gearman to process the actual job means I can get proper job logging etc.
Is this the best way to approach this and do you have any alternative ideas?
The reason I have opted for Gearman over other queue solutions is that it has a PHP extension.
The code I am writing is used to maintain a queue of emails that need to be sent out. So I may specify that I want to send an email to [email protected] at 9.50 on Friday for example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我决定采用我的问题中最初提出的
at
路线。为此,我为at
二进制文件编写了一个 PHP 包装器,并在 Ubuntu 上进行了测试。如果您有兴趣,可以在 github 上找到它: http://github.com /treffynnon/PHP-at-Job-Queue-WrapperI have decided to go the
at
route as originally laid out in my question. For the purpose I have written a little PHP wrapper for theat
binary and tested it on Ubuntu. If you are interested it can be found on github: http://github.com/treffynnon/PHP-at-Job-Queue-Wrapper一个相当老套的解决方案,只能在每小时或每天的分辨率下运行良好,是让作业(功能)名称包含您希望发送的日期。然后让工作人员每小时或每天在 cron 中开始注册这些工作。
例如,如果您想在 2012 年 3 月 12 日星期一上午 9 点发送电子邮件,请向队列中添加一个名称类似于 email_2012-03-12_09:00 的作业。然后每小时运行一个 cron 作业,该作业运行一个注册任何与 email_ + 当前日期和时间匹配的作业的工作人员。
正如我所说,可能可行,但相当老套!
更新1:我最近看到gearmand数据库的文档persistence 现在提到一个名为 when_to_run 的字段,它是一个 INT,并且可能保存一个 Unix 纪元时间戳。代码中似乎还没有引用该字段。
A rather hacky solution, which would only work well at hourly or daily resolution would be to make the job (function) name contain the date at which you wanted it sent. Then have workers starting in cron every hour or day to register for those jobs.
For example, if you wanted to send an email at 9AM on Monday March 12th 2012, add a job to the queue with a name like email_2012-03-12_09:00. Then have a cron job running hourly, which runs a worker who registers for any jobs matching email_ + current date and hour.
As I say, probably workable, but rather hacky!
UPDATE 1: I saw recently that the docs for gearmand database persistence now mention a field named when_to_run which is an INT, and could potentially hold a unix epoch timestamp. This field doesn't seem to be referenced in the code yet.
如果您使用 Zend...
https://github.com/juriansluiman/SlmQueue
If you are using Zend...
https://github.com/juriansluiman/SlmQueue