-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feat: Change JobInitializer signature * Feat+Refactor: Separate listener into a class * Test: Update tests
- Loading branch information
Showing
12 changed files
with
408 additions
and
83 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
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,97 @@ | ||
<?php | ||
|
||
namespace Mpyw\LaravelCachedDatabaseStickiness; | ||
|
||
use Illuminate\Queue\Events\JobExceptionOccurred; | ||
use Illuminate\Queue\Events\JobFailed; | ||
use Illuminate\Queue\Events\JobProcessed; | ||
use Illuminate\Queue\Events\JobProcessing; | ||
use Mpyw\LaravelCachedDatabaseStickiness\Events\ConnectionCreated; | ||
use Mpyw\LaravelCachedDatabaseStickiness\Events\RecordsHaveBeenModified; | ||
|
||
class StickinessEventListener | ||
{ | ||
/** | ||
* @var \Mpyw\LaravelCachedDatabaseStickiness\StickinessManager | ||
*/ | ||
protected $stickiness; | ||
|
||
/** | ||
* @var null|\Illuminate\Queue\Events\JobProcessing | ||
*/ | ||
protected $currentJobProcessingEvent; | ||
|
||
/** | ||
* StickinessEventListener constructor. | ||
* | ||
* @param \Mpyw\LaravelCachedDatabaseStickiness\StickinessManager $stickiness | ||
*/ | ||
public function __construct(StickinessManager $stickiness) | ||
{ | ||
$this->stickiness = $stickiness; | ||
} | ||
|
||
/** | ||
* Called when JobProcessing dispatched. | ||
* | ||
* @param \Illuminate\Queue\Events\JobProcessing $event | ||
*/ | ||
public function onJobProcessing(JobProcessing $event): void | ||
{ | ||
$this->stickiness->initializeStickinessState($this->currentJobProcessingEvent = $event); | ||
} | ||
|
||
/** | ||
* Called when JobProcessed dispatched. | ||
* | ||
* @param \Illuminate\Queue\Events\JobProcessed $event | ||
*/ | ||
public function onJobProcessed(JobProcessed $event): void | ||
{ | ||
$this->currentJobProcessingEvent = null; | ||
} | ||
|
||
/** | ||
* Called when JobExceptionOccurred dispatched. | ||
* | ||
* @param \Illuminate\Queue\Events\JobExceptionOccurred $event | ||
*/ | ||
public function onJobExceptionOccurred(JobExceptionOccurred $event): void | ||
{ | ||
$this->currentJobProcessingEvent = null; | ||
} | ||
|
||
/** | ||
* Called when JobFailed dispatched. | ||
* | ||
* @param \Illuminate\Queue\Events\JobFailed $event | ||
*/ | ||
public function onJobFailed(JobFailed $event): void | ||
{ | ||
$this->currentJobProcessingEvent = null; | ||
} | ||
|
||
/** | ||
* Called when ConnectionCreated dispatched. | ||
* | ||
* @param \Mpyw\LaravelCachedDatabaseStickiness\Events\ConnectionCreated $event | ||
*/ | ||
public function onConnectionCreated(ConnectionCreated $event): void | ||
{ | ||
if ($this->currentJobProcessingEvent) { | ||
$this->stickiness->initializeStickinessState($this->currentJobProcessingEvent, $event); | ||
} | ||
|
||
$this->stickiness->resolveRecordsModified($event->connection); | ||
} | ||
|
||
/** | ||
* Called when RecordsHaveBeenModified dispatched. | ||
* | ||
* @param \Mpyw\LaravelCachedDatabaseStickiness\Events\RecordsHaveBeenModified $event | ||
*/ | ||
public function onRecordsHaveBeenModified(RecordsHaveBeenModified $event): void | ||
{ | ||
$this->stickiness->markAsModified($event->connection); | ||
} | ||
} |
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
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,14 @@ | ||
<?php | ||
|
||
namespace Mpyw\LaravelCachedDatabaseStickiness\Tests\Stubs\Jobs; | ||
|
||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class ConnectionResolvableJob implements ShouldQueue | ||
{ | ||
public function handle(): void | ||
{ | ||
DB::connection(); | ||
} | ||
} |
Oops, something went wrong.