File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
src/Illuminate/Console/Scheduling Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,13 @@ class Event
156
156
*/
157
157
public $ exitCode ;
158
158
159
+ /**
160
+ * The mutex name resolver callback.
161
+ *
162
+ * @var \Closure|null
163
+ */
164
+ public $ createMutexNameCallback ;
165
+
159
166
/**
160
167
* Create a new event instance.
161
168
*
@@ -935,9 +942,28 @@ public function preventOverlapsUsing(EventMutex $mutex)
935
942
*/
936
943
public function mutexName ()
937
944
{
945
+ $ createMutexNameUsing = $ this ->createMutexNameCallback ;
946
+
947
+ if (! is_null ($ createMutexNameUsing ) && is_callable ($ createMutexNameUsing )) {
948
+ return $ createMutexNameUsing ($ this );
949
+ }
950
+
938
951
return 'framework ' .DIRECTORY_SEPARATOR .'schedule- ' .sha1 ($ this ->expression .$ this ->command );
939
952
}
940
953
954
+ /**
955
+ * Set the mutex name resolver callback.
956
+ *
957
+ * @param \Closure $callback
958
+ * @return $this
959
+ */
960
+ public function createMutexNameUsing (Closure $ callback )
961
+ {
962
+ $ this ->createMutexNameCallback = $ callback ;
963
+
964
+ return $ this ;
965
+ }
966
+
941
967
/**
942
968
* Delete the mutex for the event.
943
969
*
Original file line number Diff line number Diff line change 4
4
5
5
use Illuminate \Console \Scheduling \Event ;
6
6
use Illuminate \Console \Scheduling \EventMutex ;
7
+ use Illuminate \Support \Str ;
7
8
use Mockery as m ;
8
9
use PHPUnit \Framework \TestCase ;
9
10
@@ -94,4 +95,18 @@ public function testNextRunDate()
94
95
95
96
$ this ->assertSame ('10:15:00 ' , $ event ->nextRunDate ()->toTimeString ());
96
97
}
98
+
99
+ public function testCustomMutexName ()
100
+ {
101
+ $ event = new Event (m::mock (EventMutex::class), 'php -i ' );
102
+ $ event ->description ('Fancy command description ' );
103
+
104
+ $ this ->assertSame ('framework/schedule-eeb46c93d45e928d62aaf684d727e213b7094822 ' , $ event ->mutexName ());
105
+
106
+ $ event ->createMutexNameUsing (function (Event $ event ) {
107
+ return Str::slug ($ event ->description );
108
+ });
109
+
110
+ $ this ->assertSame ('fancy-command-description ' , $ event ->mutexName ());
111
+ }
97
112
}
You can’t perform that action at this time.
0 commit comments