6

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.

4
  • 6
    This is because us Germans, we do our jobs straight away. We don't need no scheduling.
    – Pekka
    Aug 23, 2010 at 12:34
  • 1
    Very funny! Seems all Gearman questions are riffed on in this way.
    – Treffynnon
    Aug 23, 2010 at 12:37
  • 2
    @Treffynnon yeah, they invite that.... They are too often put in the right way ("How to stop a gearman worker", "kill gearman workers with one command"....) :)
    – Pekka
    Aug 23, 2010 at 12:41
  • 1
    Just do that, have a cron job call Gearman. Aug 23, 2010 at 13:00

3 Answers 3

2

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

1

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.

0

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.