-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
namespace Dusterio\AwsWorker\Exceptions; | ||
|
||
class ExpiredJobException extends \Exception { | ||
} |
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,42 @@ | ||
<?php | ||
|
||
namespace Dusterio\AwsWorker\Jobs; | ||
|
||
use Dusterio\AwsWorker\Exceptions\ExpiredJobException; | ||
use Illuminate\Contracts\Queue\Job; | ||
use Illuminate\Queue\CallQueuedHandler as LaravelHandler; | ||
|
||
class CallQueuedHandler extends LaravelHandler { | ||
/** | ||
* Dispatch the given job / command through its specified middleware. | ||
* | ||
* @param \Illuminate\Contracts\Queue\Job $job | ||
* @param mixed $command | ||
* @return mixed | ||
*/ | ||
protected function dispatchThroughMiddleware(Job $job, $command) | ||
{ | ||
if ($this->hasExpired($command, $job->timestamp())) { | ||
throw new ExpiredJobException("This job has already expired"); | ||
} | ||
|
||
return parent::dispatchThroughMiddleware($job, $command); | ||
} | ||
|
||
/** | ||
* @param $command | ||
* @param $queuedAt | ||
* @return bool | ||
*/ | ||
protected function hasExpired($command, $queuedAt) { | ||
if (! property_exists($command, 'class')) { | ||
return false; | ||
} | ||
|
||
if (! property_exists($command->class, 'retention')) { | ||
return false; | ||
} | ||
|
||
return time() > $queuedAt + $command->class::$retention; | ||
} | ||
} |