-
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.
Merge pull request #5 from php-task/feature/lock
Added locking section
- Loading branch information
Showing
3 changed files
with
64 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ Contents | |
:maxdepth: 2 | ||
|
||
components | ||
locking | ||
quick-example | ||
symfony | ||
|
||
|
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,37 @@ | ||
Locking | ||
======= | ||
To avoid concurrency issues, the library is able to lock other executions which | ||
would run at the same time. This could happen if multiple workers (e.g. cronjobs) | ||
run at the same time. | ||
|
||
Each ``TaskHandler`` decides if and how many other Tasks will be blocked while a | ||
task with this handler is running. If the ``TaskHandler`` implements the | ||
``LockingTaskHandlerInterface`` the Lock-Component is enabled for this handler. | ||
The interface consists of a single method ``getLockKey($workload)`` which | ||
returns a locking-key. Tasks with the same locking-key will not be executed at | ||
the same time. | ||
|
||
Example | ||
******* | ||
|
||
.. code-block:: php | ||
<?php | ||
include __DIR__ . '/vendor/autoload.php'; | ||
class ImageResizeHandler implements Task\Lock\LockingTaskHandlerInterface | ||
{ | ||
public function handle($workload) | ||
{ | ||
... | ||
} | ||
public function getLockKey($workload) | ||
{ | ||
return self::class; | ||
// or append workload data | ||
return self::class . '-' . $workload['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