-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring custom job classes by introducing
- Loading branch information
Showing
13 changed files
with
305 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
namespace Disque\Queue; | ||
|
||
abstract class Job implements JobInterface | ||
{ | ||
/** | ||
* Job ID | ||
* | ||
* @var string | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* Job body | ||
* | ||
* @var array | ||
*/ | ||
private $body = []; | ||
|
||
/** | ||
* Build a job with the given body | ||
* | ||
* @param array $body Body | ||
*/ | ||
public function __construct(array $body = []) | ||
{ | ||
$this->setBody($body); | ||
} | ||
|
||
/** | ||
* Get job ID | ||
* | ||
* @return string | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* Set job ID | ||
* | ||
* @param string $id Id | ||
* @return void | ||
*/ | ||
public function setId($id) | ||
{ | ||
$this->id = $id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
namespace Disque\Queue\Marshal; | ||
|
||
use Disque\Queue\Job; | ||
use Disque\Queue\JobInterface; | ||
|
||
class JobMarshaler implements MarshalerInterface | ||
{ | ||
/** | ||
* Creates a JobInterface instance based on data obtained from queue | ||
* | ||
* @param string $source Source data | ||
* @return JobInterface | ||
* @throws MarshalException | ||
*/ | ||
public function unmarshal($source) | ||
{ | ||
$body = @json_decode($source, true); | ||
if (is_null($body)) { | ||
throw new MarshalException("Could not deserialize {$source}"); | ||
} | ||
return new Job($body); | ||
} | ||
|
||
/** | ||
* Marshals the body of the job ready to be put into the queue | ||
* | ||
* @param JobInterface $job Job to put in the queue | ||
* @return string Source data to be put in the queue | ||
*/ | ||
public function marshal(JobInterface $job) | ||
{ | ||
return json_encode($job->getBody()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
namespace Disque\Queue\Marshal; | ||
|
||
use Disque\Queue\QueueException; | ||
|
||
class MarshalException extends QueueException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
namespace Disque\Queue\Marshal; | ||
|
||
use Disque\Queue\JobInterface; | ||
|
||
interface MarshalerInterface | ||
{ | ||
/** | ||
* Creates a JobInterface instance based on data obtained from queue | ||
* | ||
* @param string $source Source data | ||
* @return JobInterface | ||
* @throws MarshalException | ||
*/ | ||
public function unmarshal($source); | ||
|
||
/** | ||
* Marshals the body of the job ready to be put into the queue | ||
* | ||
* @param JobInterface $job Job to put in the queue | ||
* @return string Source data to be put in the queue | ||
*/ | ||
public function marshal(JobInterface $job); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.