File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 33namespace Illuminated \Console ;
44
55use Illuminate \Console \Command ;
6+ use NinjaMutex \Lock \FlockLock ;
7+ use NinjaMutex \Mutex as Ninja ;
8+ use NinjaMutex \MutexException ;
69
710class Mutex
811{
912 private $ command ;
1013 private $ strategy ;
14+ private $ ninja ;
1115
1216 public function __construct (Command $ command )
1317 {
1418 $ this ->command = $ command ;
1519 $ this ->strategy = $ this ->strategy ();
20+ $ this ->ninja = new Ninja ('test ' , $ this ->strategy );
1621 }
1722
1823 private function strategy ()
@@ -23,11 +28,25 @@ private function strategy()
2328
2429 switch ($ this ->command ->getMutexStrategy ()) {
2530 case 'mysql ' :
26- break ;
31+ throw new MutexException ('Strategy `mysql` is not implemented yet. ' );
32+
33+ case 'redis ' :
34+ throw new MutexException ('Strategy `redis` is not implemented yet. ' );
35+
36+ case 'memcache ' :
37+ throw new MutexException ('Strategy `memcache` is not implemented yet. ' );
38+
39+ case 'memcached ' :
40+ throw new MutexException ('Strategy `memcached` is not implemented yet. ' );
2741
2842 case 'file ' :
2943 default :
30- break ;
44+ return new FlockLock ( storage_path ( ' framework ' )) ;
3145 }
3246 }
47+
48+ public function __call ($ method , $ parameters )
49+ {
50+ return call_user_func_array ([$ this ->ninja , $ method ], $ parameters );
51+ }
3352}
Original file line number Diff line number Diff line change @@ -10,8 +10,15 @@ trait WithoutOverlapping
1010 protected function execute (InputInterface $ input , OutputInterface $ output )
1111 {
1212 $ mutex = new Mutex ($ this );
13+ if (!$ mutex ->acquireLock (0 )) {
14+ $ this ->info ('Command already running! ' );
15+ return ;
16+ }
1317
14- return parent ::execute ($ input , $ output );
18+ $ code = parent ::execute ($ input , $ output );
19+ $ mutex ->releaseLock ();
20+
21+ return $ code ;
1522 }
1623
1724 public function getMutexStrategy ()
You can’t perform that action at this time.
0 commit comments