Repository navigation
Expand file tree
/
Copy pathclass-scheduler.php
More file actions
119 lines (109 loc) · 4.17 KB
/
Copy pathclass-scheduler.php
File metadata and controls
119 lines (109 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* Scheduler abstraction for Stream's deferred work.
*
* Stream defers record purging and large-table resets to a background
* scheduler so they do not block admin requests. Historically this was
* Action Scheduler (AS) exclusively. This interface decouples the calling
* code (Admin, Settings) from the concrete scheduler so the same purge
* logic can run either through Action Scheduler or through WP-Cron,
* selected at runtime via the `wp_stream_use_action_scheduler` filter.
*
* Implementations:
* - {@see AS_Scheduler} — Action Scheduler (default; bundled dependency).
* - {@see Cron_Scheduler} — WP-Cron fallback for hosts with reliable cron
* (e.g. Cavalcade) that prefer not to use AS.
*
* @package WP_Stream
*/
namespace WP_Stream;
/**
* Interface - Scheduler
*/
interface Scheduler {
/**
* Enqueue a one-off asynchronous action to run as soon as possible.
*
* Values in $args are passed positionally to the hook callback, in the
* order they appear in the array, mirroring Action Scheduler semantics.
* How the args are *stored* is backend-specific: AS keeps the array as
* given (preserving Stream's historical behavior and the keyed display
* in Tools → Scheduled Actions), while cron stores array_values(). Args
* therefore only round-trip through next_scheduled() on the backend
* that scheduled them — which is the only supported usage.
*
* @param string $hook Action hook name.
* @param array $args Arguments passed positionally to the callback.
* @param string $group Optional grouping label (used by AS; ignored by cron).
* @return void
*/
public function enqueue_async( $hook, $args = array(), $group = '' );
/**
* Schedule a recurring action if one is not already scheduled.
*
* The "already scheduled" probe may be hook-scoped (ignoring args and
* group): the AS backend intentionally checks the hook only, preserving
* Stream's historical behavior and preventing recurrences with differing
* args from stacking. Callers must treat one recurring action per hook
* as the contract; the sole caller schedules with empty args.
*
* @param int $timestamp First run, as a Unix timestamp.
* @param int $interval Recurrence interval in seconds.
* @param string $hook Action hook name.
* @param array $args Arguments passed positionally to the callback.
* @param string $group Optional grouping label (used by AS; ignored by cron).
* @return void
*/
public function schedule_recurring( $timestamp, $interval, $hook, $args = array(), $group = '' );
/**
* Get the next scheduled timestamp for a hook (with matching args).
*
* @param string $hook Action hook name.
* @param array $args Arguments the action was scheduled with.
* @return int|false Unix timestamp of the next run, or false if none.
*/
public function next_scheduled( $hook, $args = array() );
/**
* Whether any instance of a hook is scheduled, regardless of its args.
*
* @param string $hook Action hook name.
* @return bool
*/
public function has_scheduled( $hook );
/**
* Whether any of the given hooks is pending or currently in progress.
*
* Used as the auto-purge overlap guard and to drive the Settings UI
* "currently running" notices.
*
* @param array $hooks Action hook names to probe.
* @return bool
*/
public function any_pending_or_running( $hooks );
/**
* Unschedule every pending instance of a hook.
*
* @param string $hook Action hook name.
* @return void
*/
public function unschedule_all( $hook );
/**
* Mark a deferred-work context as actively running.
*
* No-op for schedulers that track in-progress state natively (AS). The
* cron fallback uses it to bridge the window between a callback starting
* and the next chained event being scheduled, so the overlap guard does
* not report "idle" mid-chain.
*
* @param string $context Short identifier for the running work.
* @return void
*/
public function mark_running( $context );
/**
* Clear the running marker set by {@see Scheduler::mark_running()}.
*
* @param string $context Short identifier for the running work.
* @return void
*/
public function mark_done( $context );
}