Verified Commit 3aef3144 authored by Erick Hitter's avatar Erick Hitter
Browse files

Allow lock limit to be varied when applied

parent 00e14768
......@@ -6,15 +6,20 @@ class Lock {
/**
* Set a lock and limit how many concurrent jobs are permitted
*/
public static function check_lock( $lock ) {
public static function check_lock( $lock, $limit = null ) {
// Prevent deadlock
if ( self::get_lock_timestamp( $lock ) < time() - JOB_TIMEOUT_IN_MINUTES * MINUTE_IN_SECONDS ) {
self::reset_lock( $lock );
return true;
}
// Default limit for concurrent events
if ( ! is_numeric( $limit ) ) {
$limit = JOB_CONCURRENCY_LIMIT;
}
// Check if process can run
if ( self::get_lock_value( $lock ) >= JOB_CONCURRENCY_LIMIT ) {
if ( self::get_lock_value( $lock ) >= $limit ) {
return false;
} else {
wp_cache_incr( self::get_key( $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