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 @@ -149,6 +149,13 @@ class Event
149
149
*/
150
150
public $ mutex ;
151
151
152
+ /**
153
+ * The mutex name resolver callback.
154
+ *
155
+ * @var \Closure|null
156
+ */
157
+ public $ mutexNameResolver ;
158
+
152
159
/**
153
160
* The exit status code of the command.
154
161
*
@@ -935,9 +942,28 @@ public function preventOverlapsUsing(EventMutex $mutex)
935
942
*/
936
943
public function mutexName ()
937
944
{
945
+ $ mutexNameResolver = $ this ->mutexNameResolver ;
946
+
947
+ if (! is_null ($ mutexNameResolver ) && is_callable ($ mutexNameResolver )) {
948
+ return $ mutexNameResolver ($ 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 or name resolver callback.
956
+ *
957
+ * @param \Closure|string $mutexName
958
+ * @return $this
959
+ */
960
+ public function createMutexNameUsing (Closure |string $ mutexName )
961
+ {
962
+ $ this ->mutexNameResolver = is_string ($ mutexName ) ? fn () => $ mutexName : $ mutexName ;
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 ' .DIRECTORY_SEPARATOR .'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