Skip to content

Latest commit

 

History

History
41 lines (26 loc) · 1.05 KB

Execute_or_Queue.md

File metadata and controls

41 lines (26 loc) · 1.05 KB

Execute or Queue

Now if our application wants to send an e-mail...

$mailJob = new EMail("test@myproject.xyz", "Hello?", "This is a test mail.");

...then it can either do that right away, delaying the application's response and requiring exception handling:

$mailJob->send();  // this might throw a RuntimeException!

Or it can put the job in a work queue for later execution:

use mle86\WQ\WorkServerAdapter\BeanstalkdWorkServer;

$workServer = BeanstalkdWorkServer::connect("localhost");
$workServer->storeJob("mail", $mailJob);

This serializes the $mailJob and puts in into the “mail” work queue of the local Beanstalkd work server.

(BeanstalkdWorkServer is an implementation of the WorkServerAdapter interface. It is provided in the mle86/wq-beanstalkd package.)

Alright, the job is now in the work queue. What next?

See next: Work the Queue.