Commit 6770a263 authored by Erick Hitter's avatar Erick Hitter Committed by GitHub
Browse files

Merge pull request #72 from Automattic/develop

Fix timeouts on event-level locking
parents 928d30f0 0235f0ae
......@@ -184,7 +184,7 @@ class Events extends Singleton {
* @param $event array Event data
*/
private function prime_event_action_lock( $event ) {
Lock::prime_lock( $this->get_lock_key_for_event_action( $event ), JOB_LOCK_EXPIRY_IN_MINUTES );
Lock::prime_lock( $this->get_lock_key_for_event_action( $event ), JOB_LOCK_EXPIRY_IN_MINUTES * \MINUTE_IN_SECONDS );
}
/**
......@@ -206,7 +206,7 @@ class Events extends Singleton {
}
// Limit to one concurrent execution of a specific action
if ( ! Lock::check_lock( $this->get_lock_key_for_event_action( $event ), 1, JOB_LOCK_EXPIRY_IN_MINUTES ) ) {
if ( ! Lock::check_lock( $this->get_lock_key_for_event_action( $event ), 1, JOB_LOCK_EXPIRY_IN_MINUTES * \MINUTE_IN_SECONDS ) ) {
return false;
}
......@@ -226,7 +226,7 @@ class Events extends Singleton {
}
// Reset individual event lock
Lock::reset_lock( $this->get_lock_key_for_event_action( $event ), JOB_LOCK_EXPIRY_IN_MINUTES );
Lock::reset_lock( $this->get_lock_key_for_event_action( $event ), JOB_LOCK_EXPIRY_IN_MINUTES * \MINUTE_IN_SECONDS );
}
/**
......
......@@ -5,12 +5,16 @@ namespace Automattic\WP\Cron_Control;
class Lock {
/**
* Set a lock and limit how many concurrent jobs are permitted
*
* @param $lock string Lock name
* @param $limit int Concurrency limit
* @param $timeout int Timeout in seconds
*
* @return bool
*/
public static function check_lock( $lock, $limit = null, $timeout_in_minutes = null ) {
public static function check_lock( $lock, $limit = null, $timeout = null ) {
// Timeout, should a process die before its lock is freed
if ( is_numeric( $timeout_in_minutes ) ) {
$timeout = $timeout_in_minutes * \MINUTE_IN_SECONDS;
} else {
if ( ! is_numeric( $timeout ) ) {
$timeout = LOCK_DEFULT_TIMEOUT_IN_MINUTES * \MINUTE_IN_SECONDS;
}
......
Supports Markdown
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