-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The main Presque class is now used as a factory
The Presque class can be used to create all the Worker / Job / Queue instances. There are factory objects for each of those 3 types. Each of the factory objects can be injected to the Presque constructor, allowing for lots of possibilities.
- Loading branch information
1 parent
1d6d72c
commit 99b3e15
Showing
11 changed files
with
432 additions
and
2 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,20 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque\Job; | ||
|
||
class JobFactory implements JobFactoryInterface | ||
{ | ||
public function create($class, array $args = array()) | ||
{ | ||
return new Job($class, $args); | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque\Job; | ||
|
||
interface JobFactoryInterface | ||
{ | ||
function create($class, array $args = array()); | ||
} |
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,22 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque\Queue; | ||
|
||
use Presque\Storage\StorageInterface; | ||
|
||
class QueueFactory implements QueueFactoryInterface | ||
{ | ||
public function create($name, StorageInterface $storage = null, $timeout = 10) | ||
{ | ||
return new Queue($name, $storage, $timeout); | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque\Queue; | ||
|
||
interface QueueFactoryInterface | ||
{ | ||
function create($name); | ||
} |
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,20 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque\Worker; | ||
|
||
class WorkerFactory implements WorkerFactoryInterface | ||
{ | ||
public function create($id = null) | ||
{ | ||
return new Worker($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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque\Worker; | ||
|
||
interface WorkerFactoryInterface | ||
{ | ||
function create($id = null); | ||
} |
40 changes: 40 additions & 0 deletions
40
tests/Presque/Tests/EventListener/JobRetryListenerTest.php
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,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque\Tests\EventListener; | ||
|
||
use Presque\Tests\TestCase; | ||
use Presque\Worker\Worker; | ||
use Presque\Events; | ||
use Presque\Event\JobEvent; | ||
use Presque\EventListener\JobRetryListener; | ||
use Mockery as m; | ||
|
||
class JobRetryListenerTest extends TestCase | ||
{ | ||
public function testFailedJobIsAddedBackToQueue() | ||
{ | ||
$worker = $this->createWorkerMock(); | ||
|
||
$job = $this->createJobMock(); | ||
$job | ||
->shouldReceive('isError')->once()->andReturn(true); | ||
|
||
$queue = $this->createQueueMock(); | ||
$queue | ||
->shouldReceive('enqueue')->once()->with($job); | ||
|
||
$event = new JobEvent($job, $queue, $worker); | ||
|
||
$listener = new JobRetryListener(); | ||
$listener->onJobFinished($event); | ||
} | ||
} |
Oops, something went wrong.