FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
craft-async-queue/src/QueueCommand.php at master · ClockworkNet/craft-async-queue · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
ClockworkNet
/
craft-async-queue
Public
forked from
ostark/craft-async-queue
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
craft-async-queue
/
src
/
QueueCommand.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
75 lines (61 loc) · 1.99 KB
Breadcrumbs
craft-async-queue
/
src
/
QueueCommand.php
Copy path
File metadata and controls
75 lines (61 loc) · 1.99 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace
ostark
\
AsyncQueue
;
use
ostark
\
AsyncQueue
\
Events
\
QueueCommandEvent
;
use
ostark
\
AsyncQueue
\
Exceptions
\
PhpExecutableNotFound
;
use
Symfony
\
Component
\
Process
\
PhpExecutableFinder
;
use
yii
\
base
\
Component
;
class
QueueCommand
extends
Component
{
const
DEFAULT_SCRIPT
=
"
craft
"
;
const
DEFAULT_ARGS
=
"
queue/run
"
;
const
EVENT_PREPARE_COMMAND
=
'
prepareCommand
'
;
protected
$
scriptName
;
protected
$
scriptArgs
;
/**
* QueueCommand constructor.
*
* @param string|null $scriptName
* @param string|null $scriptArgs
* @param array $config
*/
public
function
__construct
(
string
$
scriptName
=
null
,
string
$
scriptArgs
=
null
,
array
$
config
= [])
{
parent
::
__construct
(
$
config
);
$
this
->
scriptName
=
$
scriptName
?:
self
::
DEFAULT_SCRIPT
;
$
this
->
scriptArgs
=
$
scriptArgs
?:
self
::
DEFAULT_ARGS
;
}
/**
* @param callable|null $wrapper
*
* @return string
* @throws \ostark\AsyncQueue\Exceptions\PhpExecutableNotFound
*/
public
function
getPreparedCommand
(
callable
$
wrapper
=
null
):
string
{
$
finder
=
new
PhpExecutableFinder
();
$
php
=
$
finder
->
find
(
false
);
if
(
false
===
$
php
) {
throw
new
PhpExecutableNotFound
(
'
Unable to find php executable.
'
);
}
$
commandLine
=
join
(
"
"
, [
$
php
,
$
this
->
scriptName
,
$
this
->
scriptArgs
]);
return
$
this
->
decorate
(
$
commandLine
);
}
/**
* Wrapper
*
* @param string $commandLine
*
* @return string
*/
protected
function
decorate
(
string
$
commandLine
):
string
{
// Allow others to decorate the command
$
event
=
new
QueueCommandEvent
([
'
commandLine
'
=>
$
commandLine
]);
$
this
->
trigger
(
self
::
EVENT_PREPARE_COMMAND
,
$
event
);
$
commandLine
=
$
event
->
commandLine
;
if
(
$
event
->
useDefaultDecoration
===
false
) {
return
$
commandLine
;
}
// default decoration
return
"
nice
$
commandLine
> /dev/null 2>&1 &
"
;
}
}
Back
|
FazBrowse Home
|
New Git URL