在 Gearman 中安排特定日期和时间的作业

发布于 2024-09-15 05:42:05 字数 543 浏览 12 评论 0原文

据我所知,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

从来不烧饼 2024-09-22 05:42:05

我决定采用我的问题中最初提出的 at 路线。为此,我为 at 二进制文件编写了一个 PHP 包装器,并在 Ubuntu 上进行了测试。如果您有兴趣,可以在 github 上找到它: http://github.com /treffynnon/PHP-at-Job-Queue-Wrapper

I 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 the at 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

眼眸里的那抹悲凉 2024-09-22 05:42:05

一个相当老套的解决方案,只能在每小时或每天的分辨率下运行良好,是让作业(功能)名称包含您希望发送的日期。然后让工作人员每小时或每天在 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.

杀お生予夺 2024-09-22 05:42:05

如果您使用 Zend...

SlmQueue是一个作业队列抽象层。它允许您在 Zend Framework 2 应用程序中轻松使用作业队列系统。因此,它不会强制您专门使用一种类型的作业队列。您可以独立于底层系统编写代码和作业。这实现了系统的极大灵活性和解耦。

https://github.com/juriansluiman/SlmQueue

If you are using Zend...

SlmQueue is a job queue abstraction layer. It allows you to easily use job queue systems in a Zend Framework 2 application. Thereby it does not enforce you to specifically use one type of job queue. You can write your code and jobs independent of the underlying system. This enables great flexibility and decoupling of the systems.

https://github.com/juriansluiman/SlmQueue

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文