Commit 086ef4a 1 parent 593a4d2 commit 086ef4a Copy full SHA for 086ef4a
File tree 1 file changed +20
-14
lines changed
1 file changed +20
-14
lines changed Original file line number Diff line number Diff line change 7
7
8
8
trait WithoutOverlapping
9
9
{
10
+ protected function initialize (InputInterface $ input , OutputInterface $ output )
11
+ {
12
+ $ this ->initializeMutex ();
13
+
14
+ parent ::initialize ($ input , $ output );
15
+ }
16
+
17
+ protected function initializeMutex ()
18
+ {
19
+ $ mutex = new Mutex ($ this );
20
+ if (!$ mutex ->acquireLock (0 )) {
21
+ $ this ->info ('Command is running now! ' );
22
+ exit ();
23
+ }
24
+
25
+ register_shutdown_function (function () use ($ mutex ) {
26
+ $ mutex ->releaseLock ();
27
+ });
28
+ }
29
+
10
30
public function getMutexStrategy ()
11
31
{
12
32
return (isset ($ this ->mutexStrategy ) ? $ this ->mutexStrategy : 'file ' );
@@ -23,18 +43,4 @@ public function getMutexName()
23
43
$ arguments = json_encode ($ this ->argument ());
24
44
return "icmutex- {$ name }- " . md5 ($ arguments );
25
45
}
26
-
27
- protected function execute (InputInterface $ input , OutputInterface $ output )
28
- {
29
- $ mutex = new Mutex ($ this );
30
- if (!$ mutex ->acquireLock (0 )) {
31
- $ this ->info ('Command is running now! ' );
32
- return ;
33
- }
34
-
35
- $ code = parent ::execute ($ input , $ output );
36
- $ mutex ->releaseLock ();
37
-
38
- return $ code ;
39
- }
40
46
}
You can’t perform that action at this time.
0 commit comments