Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
WP Plugins
Cron-Control
Commits
77d69596
Commit
77d69596
authored
Jul 13, 2017
by
Erick Hitter
Browse files
Finish namespacing orchestrate commands
parent
2d1fe2c4
Changes
4
Hide whitespace changes
Inline
Side-by-side
includes/wp-cli.php
View file @
77d69596
...
...
@@ -69,5 +69,6 @@ require __DIR__ . '/wp-cli/class-cache.php';
require
__DIR__
.
'/wp-cli/class-events.php'
;
require
__DIR__
.
'/wp-cli/class-lock.php'
;
require
__DIR__
.
'/wp-cli/class-one-time-fixers.php'
;
require
__DIR__
.
'/wp-cli/class-orchestrate.php'
;
require
__DIR__
.
'/wp-cli/class-orchestrate-runner.php'
;
require
__DIR__
.
'/wp-cli/class-rest-api.php'
;
includes/wp-cli/class-orchestrate-runner.php
View file @
77d69596
...
...
@@ -5,7 +5,7 @@ namespace Automattic\WP\Cron_Control\CLI;
/**
* Commands used by the Go-based runner to execute events
*/
class
Orchestrate
extends
\
WP_CLI_Command
{
class
Orchestrate
_Runner
extends
\
WP_CLI_Command
{
/**
* List the next set of events to run; meant for Runner
*
...
...
@@ -94,57 +94,6 @@ class Orchestrate extends \WP_CLI_Command {
\
WP_CLI\Utils\format_items
(
$format
,
$info
,
array_keys
(
$info
[
0
]
)
);
}
/**
* Check and change status of automatic event execution
*
* When using the Go-based runner, it may be necessary to stop execution for a period, or indefinitely
*
* @subcommand manage-automatic-execution
* @synopsis [--enable] [--disable] [--disable_until=<disable_until>]
*/
public
function
toggle_event_execution
(
$args
,
$assoc_args
)
{
// Update execution status
$disable_ts
=
\
WP_CLI\Utils\get_flag_value
(
$assoc_args
,
'disable_until'
,
0
);
$disable_ts
=
absint
(
$disable_ts
);
if
(
\
WP_CLI\Utils\get_flag_value
(
$assoc_args
,
'enable'
,
false
)
)
{
update_option
(
\
Automattic\WP\Cron_Control\Events
::
DISABLE_RUN_OPTION
,
0
);
\
WP_CLI
::
success
(
'Enabled'
);
return
;
}
elseif
(
\
WP_CLI\Utils\get_flag_value
(
$assoc_args
,
'disable'
,
false
)
)
{
update_option
(
\
Automattic\WP\Cron_Control\Events
::
DISABLE_RUN_OPTION
,
1
);
\
WP_CLI
::
success
(
'Disabled'
);
return
;
}
elseif
(
$disable_ts
>
0
)
{
if
(
$disable_ts
>
time
()
)
{
update_option
(
\
Automattic\WP\Cron_Control\Events
::
DISABLE_RUN_OPTION
,
$disable_ts
);
\
WP_CLI
::
success
(
sprintf
(
'Disabled until %s'
,
date
(
'Y-m-d H:i:s T'
,
$disable_ts
)
)
);
return
;
}
else
{
\
WP_CLI
::
error
(
'Timestamp is in the past.'
);
}
}
// Display existing status
$status
=
get_option
(
\
Automattic\WP\Cron_Control\Events
::
DISABLE_RUN_OPTION
,
0
);
switch
(
$status
)
{
case
0
:
$status
=
'Automatic execution is enabled'
;
break
;
case
1
:
$status
=
'Automatic execution is disabled indefinitely'
;
break
;
default
:
$status
=
sprintf
(
'Automatic execution is disabled until %s'
,
date
(
'Y-m-d H:i:s T'
,
$status
)
);
break
;
}
\
WP_CLI
::
log
(
$status
);
}
}
\
WP_CLI
::
add_command
(
'cron-control orchestrate runner'
,
'Automattic\WP\Cron_Control\CLI\Orchestrate'
);
\
WP_CLI
::
add_command
(
'cron-control orchestrate runner
-only
'
,
'Automattic\WP\Cron_Control\CLI\Orchestrate
_Runner
'
);
includes/wp-cli/class-orchestrate.php
0 → 100644
View file @
77d69596
<?php
namespace
Automattic\WP\Cron_Control\CLI
;
/**
* Commands to manage automatic event execution
*/
class
Orchestrate
extends
\
WP_CLI_Command
{
/**
* Check and change status of automatic event execution
*
* When using the Go-based runner, it may be necessary to stop execution for a period, or indefinitely
*
* @subcommand manage-automatic-execution
* @synopsis [--enable] [--disable] [--disable_until=<disable_until>]
*/
public
function
toggle_event_execution
(
$args
,
$assoc_args
)
{
// Update execution status
$disable_ts
=
\
WP_CLI\Utils\get_flag_value
(
$assoc_args
,
'disable_until'
,
0
);
$disable_ts
=
absint
(
$disable_ts
);
if
(
\
WP_CLI\Utils\get_flag_value
(
$assoc_args
,
'enable'
,
false
)
)
{
update_option
(
\
Automattic\WP\Cron_Control\Events
::
DISABLE_RUN_OPTION
,
0
);
\
WP_CLI
::
success
(
'Enabled'
);
return
;
}
elseif
(
\
WP_CLI\Utils\get_flag_value
(
$assoc_args
,
'disable'
,
false
)
)
{
update_option
(
\
Automattic\WP\Cron_Control\Events
::
DISABLE_RUN_OPTION
,
1
);
\
WP_CLI
::
success
(
'Disabled'
);
return
;
}
elseif
(
$disable_ts
>
0
)
{
if
(
$disable_ts
>
time
()
)
{
update_option
(
\
Automattic\WP\Cron_Control\Events
::
DISABLE_RUN_OPTION
,
$disable_ts
);
\
WP_CLI
::
success
(
sprintf
(
'Disabled until %s'
,
date
(
'Y-m-d H:i:s T'
,
$disable_ts
)
)
);
return
;
}
else
{
\
WP_CLI
::
error
(
'Timestamp is in the past.'
);
}
}
// Display existing status
$status
=
get_option
(
\
Automattic\WP\Cron_Control\Events
::
DISABLE_RUN_OPTION
,
0
);
switch
(
$status
)
{
case
0
:
$status
=
'Automatic execution is enabled'
;
break
;
case
1
:
$status
=
'Automatic execution is disabled indefinitely'
;
break
;
default
:
$status
=
sprintf
(
'Automatic execution is disabled until %s'
,
date
(
'Y-m-d H:i:s T'
,
$status
)
);
break
;
}
\
WP_CLI
::
log
(
$status
);
}
}
\
WP_CLI
::
add_command
(
'cron-control orchestrate'
,
'Automattic\WP\Cron_Control\CLI\Orchestrate'
);
runner/runner.go
View file @
77d69596
...
...
@@ -80,6 +80,7 @@ func main() {
go
heartbeat
()
caughtSig
:=
<-
sig
close
(
sites
)
close
(
events
)
logger
.
Printf
(
"Stopping, got signal %s"
,
caughtSig
)
}
...
...
@@ -158,7 +159,7 @@ func getSites() ([]Site, error) {
}
func
getInstanceInfo
()
(
SiteInfo
,
error
)
{
raw
,
err
:=
runWpCliCmd
([]
string
{
"cron-control"
,
"orchestrate"
,
"runner"
,
"get-info"
,
"--format=json"
})
raw
,
err
:=
runWpCliCmd
([]
string
{
"cron-control"
,
"orchestrate"
,
"runner
-only
"
,
"get-info"
,
"--format=json"
})
if
err
!=
nil
{
return
SiteInfo
{},
err
}
...
...
@@ -241,7 +242,7 @@ func queueSiteEvents(workerId int, sites <-chan Site, queue chan<- Event) {
}
func
getSiteEvents
(
site
string
)
([]
Event
,
error
)
{
raw
,
err
:=
runWpCliCmd
([]
string
{
"cron-control"
,
"orchestrate"
,
"runner"
,
"list-due-batch"
,
fmt
.
Sprintf
(
"--url=%s"
,
site
),
"--format=json"
})
raw
,
err
:=
runWpCliCmd
([]
string
{
"cron-control"
,
"orchestrate"
,
"runner
-only
"
,
"list-due-batch"
,
fmt
.
Sprintf
(
"--url=%s"
,
site
),
"--format=json"
})
if
err
!=
nil
{
return
make
([]
Event
,
0
),
err
}
...
...
@@ -256,7 +257,7 @@ func getSiteEvents(site string) ([]Event, error) {
func
runEvents
(
workerId
int
,
events
<-
chan
Event
)
{
for
event
:=
range
events
{
subcommand
:=
[]
string
{
"cron-control"
,
"orchestrate"
,
"runner"
,
"run"
,
fmt
.
Sprintf
(
"--timestamp=%d"
,
event
.
Timestamp
),
fmt
.
Sprintf
(
"--action=%s"
,
event
.
Action
),
fmt
.
Sprintf
(
"--instance=%s"
,
event
.
Instance
),
fmt
.
Sprintf
(
"--url=%s"
,
event
.
Url
),
fmt
.
Sprintf
(
"--network=%d"
,
wpNetwork
)}
subcommand
:=
[]
string
{
"cron-control"
,
"orchestrate"
,
"runner
-only
"
,
"run"
,
fmt
.
Sprintf
(
"--timestamp=%d"
,
event
.
Timestamp
),
fmt
.
Sprintf
(
"--action=%s"
,
event
.
Action
),
fmt
.
Sprintf
(
"--instance=%s"
,
event
.
Instance
),
fmt
.
Sprintf
(
"--url=%s"
,
event
.
Url
),
fmt
.
Sprintf
(
"--network=%d"
,
wpNetwork
)}
runWpCliCmd
(
subcommand
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment