File tree Expand file tree Collapse file tree 3 files changed +64
-8
lines changed Expand file tree Collapse file tree 3 files changed +64
-8
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ Contents
3030 :maxdepth: 2
3131
3232 components
33+ locking
3334 quick-example
3435 symfony
3536
Original file line number Diff line number Diff line change 1+ Locking
2+ =======
3+ To avoid concurrency issues, the library is able to lock other executions which
4+ would run at the same time. This could happen if multiple workers (e.g. cronjobs)
5+ run at the same time.
6+
7+ Each ``TaskHandler `` decides if and how many other Tasks will be blocked while a
8+ task with this handler is running. If the ``TaskHandler `` implements the
9+ ``LockingTaskHandlerInterface `` the Lock-Component is enabled for this handler.
10+ The interface consists of a single method ``getLockKey($workload) `` which
11+ returns a locking-key. Tasks with the same locking-key will not be executed at
12+ the same time.
13+
14+ Example
15+ *******
16+
17+ .. code-block :: php
18+
19+ <?php
20+
21+ include __DIR__ . '/vendor/autoload.php';
22+
23+ class ImageResizeHandler implements Task\Lock\LockingTaskHandlerInterface
24+ {
25+ public function handle($workload)
26+ {
27+ ...
28+ }
29+
30+ public function getLockKey($workload)
31+ {
32+ return self::class;
33+
34+ // or append workload data
35+ return self::class . '-' . $workload['id'];
36+ }
37+ }
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ Additional features which are implemented in this bundle.
1212* Persist tasks and executions in database
1313* Run statistics foreach execution of tasks
1414* Predefined system-tasks
15+ * Locking mechanism to avoid concurrency problems
1516
1617Installation
1718------------
5455
5556System-Tasks
5657------------
57-
5858System-tasks can be used to predefine tasks for deployment. The developer
5959can define which handler will be called (with an ``cron_expression `` and
6060a ``workload ``). This tasks can be scheduled with the following command.
@@ -79,23 +79,41 @@ supported.
7979After addition or changing in the config you have to run the command again
8080to be sure that the task-table will be updated.
8181
82+ Locking
83+ -------
84+ Locking is used to avoid concurrency problems when multiple task-runners run at
85+ the same time (see :doc: `locking `). This feature has to be enabled and will have
86+ multiple different storages in the future.
87+
88+ Currently only file storage is implemented and usable.
89+
8290Configuration Reference
8391-----------------------
8492
8593.. code-block :: yaml
86-
8794 task :
88- storage : doctrine # One of "array"; "doctrine"
95+ storage : doctrine # One of "array"; "doctrine"
8996 adapters :
9097 doctrine :
91- clear : true
98+ clear : true
9299 run :
93100 mode : ' off' # One of "off"; "listener"
101+ locking :
102+ enabled : false
103+ storage : file # One of "file"
104+ ttl : 600
105+ storages :
106+ file :
107+ directory : ' %kernel.cache_dir%/tasks'
94108 system_tasks :
95- enabled : true
96- handler_class : ~
97- workload : null
98- cron_expression : ~
109+
110+ # Prototype
111+ -
112+ enabled : true
113+ handler_class : ~
114+ workload : null
115+ cron_expression : ~
116+
99117
100118 .. _fastcgi_finish_request : http://php.net/manual/en/function.fastcgi-finish-request.php
101119.. _PHP FPM : http://php.net/manual/en/install.fpm.php
You can’t perform that action at this time.
0 commit comments