Tristan Bailey
1 min readOct 17, 2016

--

No not that, dispatch is find to start the job, this is what I do using the framework.

Just the logic in the handle() method, try and keep like you would treat a controller. Pass calls along or choose to fail, not if this then that, do a filter, and anther thing, and then its a small class of logic in the job, maybe even other methods in the object.

Instead, keep the handle small.

So we needed to do some api calls in a job, they started with try catch blocks around the api call inside the handle() {} But this means we cant use them in another file and cant test them.

So we made a new service class for ExternalApi and then in the handle() of the job we new that class and call methods in that and then save and fire an Event that job is done.

This way we can have unit tests on the ExternalApi and use it in the rest of site. Job file looks more like this, sort of. Just no biz logic or things we want to test so much

handle() {

$api = new ExternalApi($this->class->var);

$result = $api->fetch();

$this->class->result = $result;

$this->class->save();

}

--

--

Tristan Bailey

Working with B2B and Manufacturing to build better web Sales and Apps for their customers. Web Development agency https://holdingbay.co.uk #Brighton / #Koln