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
dd2c1d63
Verified
Commit
dd2c1d63
authored
Dec 08, 2016
by
Erick Hitter
Browse files
Introduce function to check runtime lock
See #28
parent
54f2be0b
Changes
3
Hide whitespace changes
Inline
Side-by-side
includes/class-lock.php
View file @
dd2c1d63
...
...
@@ -72,21 +72,21 @@ class Lock {
/**
* Retrieve a lock from cache
*/
p
rivate
static
function
get_lock_value
(
$lock
)
{
p
ublic
static
function
get_lock_value
(
$lock
)
{
return
(
int
)
wp_cache_get
(
self
::
get_key
(
$lock
),
null
,
true
);
}
/**
* Retrieve a lock's timestamp
*/
p
rivate
static
function
get_lock_timestamp
(
$lock
)
{
p
ublic
static
function
get_lock_timestamp
(
$lock
)
{
return
(
int
)
wp_cache_get
(
self
::
get_key
(
$lock
,
'timestamp'
),
null
,
true
);
}
/**
* Clear a lock's current values, in order to free it
*/
p
rivate
static
function
reset_lock
(
$lock
)
{
p
ublic
static
function
reset_lock
(
$lock
)
{
wp_cache_set
(
self
::
get_key
(
$lock
),
0
);
wp_cache_set
(
self
::
get_key
(
$lock
,
'timestamp'
),
time
()
);
...
...
includes/wp-cli.php
View file @
dd2c1d63
...
...
@@ -37,4 +37,5 @@ function stop_the_insanity() {
*/
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'
;
includes/wp-cli/class-lock.php
0 → 100644
View file @
dd2c1d63
<?php
namespace
Automattic\WP\Cron_Control\CLI
;
/**
* Manage Cron Control's internal locks
*/
class
Lock
extends
\
WP_CLI_Command
{
/**
* Check value of execution lock
*
* Not to exceed `JOB_CONCURRENCY_LIMIT`
*
* @subcommand check-run-lock
*/
public
function
check_run_lock
(
$args
,
$assoc_args
)
{
\
WP_CLI
::
line
(
__
(
'This lock limits the number of concurrent events that are run.'
,
'automattic-cron-control'
)
.
"
\n
"
);
\
WP_CLI
::
line
(
sprintf
(
__
(
'Maximum: %s'
,
'automattic-cron-control'
),
number_format_i18n
(
\
Automattic\WP\Cron_Control\JOB_CONCURRENCY_LIMIT
)
)
.
"
\n
"
);
$lock
=
\
Automattic\WP\Cron_Control\Lock
::
get_lock_value
(
\
Automattic\WP\Cron_Control\Events
::
LOCK
);
$timestamp
=
\
Automattic\WP\Cron_Control\Lock
::
get_lock_timestamp
(
\
Automattic\WP\Cron_Control\Events
::
LOCK
);
\
WP_CLI
::
line
(
sprintf
(
__
(
'Current value: %s'
,
'automattic-cron-control'
),
number_format_i18n
(
$lock
)
)
);
\
WP_CLI
::
line
(
sprintf
(
__
(
'Lock expiration: %s GMT'
,
'automattic-cron-control'
),
date
(
TIME_FORMAT
,
$timestamp
)
)
);
}
}
\
WP_CLI
::
add_command
(
'cron-control locks'
,
'Automattic\WP\Cron_Control\CLI\Lock'
);
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