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
30
30
:maxdepth: 2
31
31
32
32
components
33
+ locking
33
34
quick-example
34
35
symfony
35
36
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.
12
12
* Persist tasks and executions in database
13
13
* Run statistics foreach execution of tasks
14
14
* Predefined system-tasks
15
+ * Locking mechanism to avoid concurrency problems
15
16
16
17
Installation
17
18
------------
54
55
55
56
System-Tasks
56
57
------------
57
-
58
58
System-tasks can be used to predefine tasks for deployment. The developer
59
59
can define which handler will be called (with an ``cron_expression `` and
60
60
a ``workload ``). This tasks can be scheduled with the following command.
@@ -79,23 +79,41 @@ supported.
79
79
After addition or changing in the config you have to run the command again
80
80
to be sure that the task-table will be updated.
81
81
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
+
82
90
Configuration Reference
83
91
-----------------------
84
92
85
93
.. code-block :: yaml
86
-
87
94
task :
88
- storage : doctrine # One of "array"; "doctrine"
95
+ storage : doctrine # One of "array"; "doctrine"
89
96
adapters :
90
97
doctrine :
91
- clear : true
98
+ clear : true
92
99
run :
93
100
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'
94
108
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
+
99
117
100
118
.. _fastcgi_finish_request : http://php.net/manual/en/function.fastcgi-finish-request.php
101
119
.. _PHP FPM : http://php.net/manual/en/install.fpm.php
You can’t perform that action at this time.
0 commit comments