File tree Expand file tree Collapse file tree 4 files changed +23
-22
lines changed Expand file tree Collapse file tree 4 files changed +23
-22
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env php
2
+ <?php
3
+
4
+ if (file_exists (__DIR__ . '/../vendor/autoload.php ' )) {
5
+ require_once __DIR__ . '/../vendor/autoload.php ' ;
6
+ } else {
7
+ require_once __DIR__ . '/../../../autoload.php ' ;
8
+ }
9
+
10
+ parse_str ($ argv [2 ], $ config );
11
+
12
+ $ cls = $ config ['jobClass ' ];
13
+
14
+ if (!is_a ($ cls , 'Jobby\BackgroundJob ' , true )) {
15
+ throw new Jobby \Exception ('"jobClass" needs to be an instanceof Jobby\BackgroundJob ' );
16
+ }
17
+
18
+ /** @var \Jobby\BackgroundJob $job */
19
+ $ job = new $ cls ($ argv [1 ], $ config );
20
+ $ job ->run ();
Original file line number Diff line number Diff line change @@ -284,23 +284,3 @@ protected function runFile()
284
284
}
285
285
}
286
286
}
287
-
288
- // run this file, if executed directly
289
- // @see: http://stackoverflow.com/questions/2413991/php-equivalent-of-pythons-name-main
290
- // @codeCoverageIgnoreStart
291
- $ trace = debug_backtrace (DEBUG_BACKTRACE_IGNORE_ARGS , 1 );
292
- if (!empty ($ trace )) {
293
- return ;
294
- }
295
-
296
- if (file_exists (__DIR__ . '/../vendor/autoload.php ' )) {
297
- require_once __DIR__ . '/../vendor/autoload.php ' ;
298
- } else {
299
- require_once __DIR__ . '/../../../autoload.php ' ;
300
- }
301
-
302
- global $ argv ;
303
- parse_str ($ argv [2 ], $ config );
304
- $ job = new BackgroundJob ($ argv [1 ], $ config );
305
- $ job ->run ();
306
- // @codeCoverageIgnoreEnd
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ public function __construct(array $config = [])
35
35
$ this ->setConfig ($ this ->getDefaultConfig ());
36
36
$ this ->setConfig ($ config );
37
37
38
- $ this ->script = __DIR__ . DIRECTORY_SEPARATOR . ' BackgroundJob.php ' ;
38
+ $ this ->script = realpath ( __DIR__ . ' /../bin/run-job ' ) ;
39
39
}
40
40
41
41
/**
@@ -56,6 +56,7 @@ protected function getHelper()
56
56
public function getDefaultConfig ()
57
57
{
58
58
return [
59
+ 'jobClass ' => 'Jobby\BackgroundJob ' ,
59
60
'recipients ' => null ,
60
61
'mailer ' => 'sendmail ' ,
61
62
'maxRuntime ' => null ,
Original file line number Diff line number Diff line change @@ -286,7 +286,7 @@ public function testShouldFailIfMaxRuntimeExceeded()
286
286
$ jobby ->run ();
287
287
sleep (2 );
288
288
$ jobby ->run ();
289
- sleep (1 );
289
+ sleep (2 );
290
290
291
291
$ this ->assertContains ('ERROR: MaxRuntime of 1 secs exceeded! ' , $ this ->getLogContent ());
292
292
}
You can’t perform that action at this time.
0 commit comments