File tree Expand file tree Collapse file tree 1 file changed +20
-14
lines changed
Expand file tree Collapse file tree 1 file changed +20
-14
lines changed Original file line number Diff line number Diff line change 77
88trait WithoutOverlapping
99{
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+
1030 public function getMutexStrategy ()
1131 {
1232 return (isset ($ this ->mutexStrategy ) ? $ this ->mutexStrategy : 'file ' );
@@ -23,18 +43,4 @@ public function getMutexName()
2343 $ arguments = json_encode ($ this ->argument ());
2444 return "icmutex- {$ name }- " . md5 ($ arguments );
2545 }
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- }
4046}
You can’t perform that action at this time.
0 commit comments