\ActionScheduler_OptionLock

Provide a way to set simple transient locks to block behaviour for up-to a given duration.

Class ActionScheduler_OptionLock

Summary

Methods
Properties
Constants
is_locked()
set()
get_expiration()
instance()
No public properties found
No constants found
get_duration()
get_key()
$lock_duration
N/A
get_expiration_from()
get_existing_lock()
new_lock_value()
$locker
N/A

Properties

$lock_duration

$lock_duration : int

Duration of lock.

Type

normal

$locker

$locker : \ActionScheduler_Lock

Instance.

Type

normal

Methods

is_locked()

is_locked(string  $lock_type) : bool

Check if a lock is set for a given lock type.

Parameters

string $lock_type

A string to identify different lock types.

Returns

bool

set()

set(string  $lock_type) : bool

Set a lock using options for a given amount of time (60 seconds by default).

Using an autoloaded option avoids running database queries or other resource intensive tasks on frequently triggered hooks, like 'init' or 'shutdown'.

For example, ActionScheduler_QueueRunner->maybe_dispatch_async_request() uses a lock to avoid calling ActionScheduler_QueueRunner->has_maximum_concurrent_batches() every time the 'shutdown', hook is triggered, because that method calls ActionScheduler_QueueRunner->store->get_claim_count() to find the current number of claims in the database.

Parameters

string $lock_type

A string to identify different lock types.

Returns

bool

get_expiration()

get_expiration(string  $lock_type) : bool|int

If a lock is set, return the timestamp it was set to expiry.

Parameters

string $lock_type

A string to identify different lock types.

Returns

bool|int —

False if no lock is set, otherwise the timestamp for when the lock is set to expire.

instance()

instance() : \ActionScheduler_Lock

Get instance.

Returns

\ActionScheduler_Lock

get_duration()

get_duration(string  $lock_type) : int

Get the amount of time to set for a given lock. 60 seconds by default.

Parameters

string $lock_type

A string to identify different lock types.

Returns

int

get_key()

get_key(string  $lock_type) : string

Get the key to use for storing the lock in the transient

Parameters

string $lock_type

A string to identify different lock types.

Returns

string

get_expiration_from()

get_expiration_from(string  $lock_value) : bool|int

Given the lock string, derives the lock expiration timestamp (or false if it cannot be determined).

Parameters

string $lock_value

String containing a timestamp, or pipe-separated combination of unique value and timestamp.

Returns

bool|int

get_existing_lock()

get_existing_lock(string  $lock_type) : string

Supplies the existing lock value, or an empty string if not set.

Parameters

string $lock_type

A string to identify different lock types.

Returns

string

new_lock_value()

new_lock_value(string  $lock_type) : string

Supplies a lock value consisting of a unique value and the current timestamp, which are separated by a pipe character.

Example: (string) "649de012e6b262.09774912|1688068114"

Parameters

string $lock_type

A string to identify different lock types.

Returns

string