Verified Commit dd2c1d63 authored by Erick Hitter's avatar Erick Hitter
Browse files

Introduce function to check runtime lock

See #28
parent 54f2be0b
...@@ -72,21 +72,21 @@ class Lock { ...@@ -72,21 +72,21 @@ class Lock {
/** /**
* Retrieve a lock from cache * Retrieve a lock from cache
*/ */
private static function get_lock_value( $lock ) { public static function get_lock_value( $lock ) {
return (int) wp_cache_get( self::get_key( $lock ), null, true ); return (int) wp_cache_get( self::get_key( $lock ), null, true );
} }
/** /**
* Retrieve a lock's timestamp * Retrieve a lock's timestamp
*/ */
private static function get_lock_timestamp( $lock ) { public static function get_lock_timestamp( $lock ) {
return (int) wp_cache_get( self::get_key( $lock, 'timestamp' ), null, true ); return (int) wp_cache_get( self::get_key( $lock, 'timestamp' ), null, true );
} }
/** /**
* Clear a lock's current values, in order to free it * Clear a lock's current values, in order to free it
*/ */
private static function reset_lock( $lock ) { public static function reset_lock( $lock ) {
wp_cache_set( self::get_key( $lock ), 0 ); wp_cache_set( self::get_key( $lock ), 0 );
wp_cache_set( self::get_key( $lock, 'timestamp' ), time() ); wp_cache_set( self::get_key( $lock, 'timestamp' ), time() );
......
...@@ -37,4 +37,5 @@ function stop_the_insanity() { ...@@ -37,4 +37,5 @@ function stop_the_insanity() {
*/ */
require __DIR__ . '/wp-cli/class-cache.php'; require __DIR__ . '/wp-cli/class-cache.php';
require __DIR__ . '/wp-cli/class-events.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-one-time-fixers.php';
<?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' );
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment