Verified Commit 675ca7c4 authored by Erick Hitter's avatar Erick Hitter
Browse files

Move all lock values to constants, mostly to simplify accompanying CLI commands

parent ea37320c
......@@ -271,7 +271,7 @@ class Cron_Options_CPT extends Singleton {
*/
public function create_or_update_job( $timestamp, $action, $args, $update_id = null ) {
// Limit how many events to insert at once
if ( ! Lock::check_lock( self::LOCK, 5 ) ) {
if ( ! Lock::check_lock( self::LOCK, JOB_CREATION_CONCURRENCY_LIMIT ) ) {
return false;
}
......
......@@ -148,7 +148,7 @@ class Events extends Singleton {
unset( $timestamp, $action, $instance );
// Limit how many events are processed concurrently
if ( ! is_internal_event( $event['action'] ) && ! Lock::check_lock( self::LOCK ) ) {
if ( ! is_internal_event( $event['action'] ) && ! Lock::check_lock( self::LOCK, JOB_CONCURRENCY_LIMIT ) ) {
return new \WP_Error( 'no-free-threads', sprintf( __( 'No resources available to run the job with action action `%1$s` and arguments `%2$s`.', 'automattic-cron-control' ), $event['action'], maybe_serialize( $event['args'] ) ), array( 'status' => 429, ) );
}
......
......@@ -15,7 +15,7 @@ class Lock {
// Default limit for concurrent events
if ( ! is_numeric( $limit ) ) {
$limit = JOB_CONCURRENCY_LIMIT;
$limit = LOCK_DEFAULT_LIMIT;
}
// Check if process can run
......
......@@ -9,3 +9,13 @@ const JOB_QUEUE_SIZE = 10;
const JOB_QUEUE_WINDOW_IN_SECONDS = 60;
const JOB_TIMEOUT_IN_MINUTES = 10;
const JOB_CONCURRENCY_LIMIT = 10;
/**
* Job creation
*/
const JOB_CREATION_CONCURRENCY_LIMIT = 5;
/**
* Locks
*/
const LOCK_DEFAULT_LIMIT = 10;
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