0

I want to extract some of the time consuming things into a queue. For this I found Gearman to be the most used but don't know if it is the right thing for me. One of the tasks we want to do is queue sending emails and want to provide the feature to be able to cancel to send the mail for 1 minute. So it should not work on the job right away but execute it at now + 1 minute. That way I can cancel the job before that and it never gets sent.

Is there a way to do this?

It will run on debian. And should be usable from php. The only thing I found so far was Schedule a job in Gearman for a specific date and time but that runs on something not widely spread :(

1 Answer 1

0

There are two parts to your question: (1) scheduling in the future and (2) being able to cancel the job until that time.

For (1) at should work just fine as specified in that question and the guy even posted his wrapper code. Have you tried it?

If you don't want to use that, consider this scenario:

  • insert an email record for the email to-be-sent in a database, including a "timeSent" column which you will set 1 minute in the future.
  • have a single gearman worker (I'll explain why single) look at the database for emails that have not been sent (eg some status column = 0) and where timeSent has already passed, and send those.

So, for (2), if you want to cancel an email before it's sent just update its status column to something else.

Your gearman worker has to be a single one because if you have multiple they might fetch and try to send the same email record. If you need multiple make sure the one that gets the email record first locks it immediately before any time consuming operations like actually emailing it (say, by updating that status column to something else).

Your Answer

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

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