ActionScheduler_ActionClaim
Represents a claim on a set of action IDs. Claims are used by the queue runner and data stores to lock a batch of pending actions for processing, preventing other processes from running them simultaneously.
Source: classes/ActionScheduler_ActionClaim.php
Properties
private string $id = ''
The claim identifier. In the DB store this corresponds to the claim_id primary key in the actionscheduler_claims table.
private int[] $action_ids = array()
List of action IDs included in the claim.
Constructor
__construct( string $id, array $action_ids )
Creates a claim instance.
$id— Claim ID.$action_ids— Array of action IDs included in the claim.
Methods
public function get_id()
Returns the claim ID.
public function get_actions()
Returns the array of claimed action IDs.
Claim Workflow (DB Store)
ActionScheduler_Store::stake_claim() is implemented by the DB store to claim a batch of actions:
-
Generate claim ID
ActionScheduler_DBStore::generate_claim_id()inserts a row into theactionscheduler_claimstable and returns the new ID.
-
Select and claim actions
ActionScheduler_DBStore::claim_actions()selects pending actions (status = pending) withclaim_id = 0andscheduled_date_gmt <= now.- Optional filters include
hooksandgroup. - Actions are ordered by
priority ASC, attempts ASC, scheduled_date_gmt ASC, action_id ASC(filterable viaaction_scheduler_claim_actions_order_by). - The DB store uses
SELECT ... FOR UPDATEand, when supported,SKIP LOCKEDto avoid deadlocks. - The matched rows are updated to set
claim_idand update attempt timestamps.
-
Resolve claimed IDs
ActionScheduler_DBStore::find_actions_by_claim_id()fetches the list of action IDs in the claim, validating each scheduled date against the original cut-off time.
-
Return a claim object
stake_claim()returns anActionScheduler_ActionClaimcontaining the claim ID and action IDs.
Releasing Claims
ActionScheduler_Store::release_claim() removes the claim and makes pending actions available for re-claiming.
In the DB store:
- Pending actions within the claim are located by ID and updated to
claim_id = 0. - The claim row is deleted from the
actionscheduler_claimstable. - If fewer rows are updated than expected, a
RuntimeExceptionis thrown.
Related Store APIs
These store methods coordinate with claims and are used by queue runners and other internal components:
ActionScheduler_Store::stake_claim()ActionScheduler_Store::get_claim_count()ActionScheduler_Store::release_claim()ActionScheduler_Store::unclaim_action()
Usage Notes
Claims are used to manage concurrency. ActionScheduler_Abstract_QueueRunner::has_maximum_concurrent_batches() consults ActionScheduler_Store::get_claim_count() to determine whether additional batches should be started. This ensures only a limited number of concurrent processors are running at once.