You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/advanced-usage.md
+61Lines changed: 61 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,6 +97,67 @@ When dispatching a duplicate task:
97
97
98
98
Prevents accidental duplication and is enabled by default.
99
99
100
+
## Task Dispatching Requirements (Since 0.0.7)
101
+
102
+
When dispatching tasks, Shepherd performs several checks:
103
+
104
+
1.**Table Registration**: Verifies that Shepherd's database tables are registered
105
+
2.**Action Scheduler**: Ensures Action Scheduler is initialized
106
+
107
+
### Synchronous Fallback When Tables Not Registered
108
+
109
+
If Shepherd's database tables are not yet registered when you dispatch a task, by default the task will be **processed immediately in a synchronous manner** instead of being queued for background processing. This ensures tasks can still execute even during early initialization phases.
110
+
111
+
```php
112
+
// If tables are not registered, this task will run immediately
113
+
shepherd()->dispatch( new My_Task() );
114
+
```
115
+
116
+
You can monitor when this synchronous processing occurs:
// Return false to skip task processing when tables are not ready
133
+
return false;
134
+
}, 10, 2 );
135
+
```
136
+
137
+
### Action Scheduler Initialization
138
+
139
+
If Action Scheduler is not yet initialized when you dispatch a task, Shepherd will automatically queue it and dispatch once Action Scheduler is ready via the `action_scheduler_init` hook.
Copy file name to clipboardExpand all lines: docs/api-reference.md
+90-2Lines changed: 90 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,15 +18,21 @@ The main orchestrator for task scheduling and processing.
18
18
19
19
#### Methods
20
20
21
-
##### `dispatch( Task $task, int $delay = 0 ): void`
21
+
##### `dispatch( Task $task, int $delay = 0 ): self`
22
22
23
23
Schedules a task for execution.
24
24
25
25
-**Parameters:**
26
26
-`$task` - The task instance to schedule
27
27
-`$delay` - Delay in seconds before execution (default: 0)
28
+
-**Returns:** The Regulator instance for method chaining
28
29
-**Throws:** and **Catches:**`ShepherdTaskAlreadyExistsException` if duplicate task exists
29
30
-**Throws:** and **Catches:**`RuntimeException` if task fails to be scheduled or inserted into the database.
31
+
-**Since 0.0.7 - Synchronous Fallback:** When Shepherd tables are not registered:
32
+
- Tasks are processed immediately in a synchronous manner by default
33
+
- Fires `shepherd_{prefix}_dispatched_sync` action when processing synchronously
34
+
- Can be disabled via `shepherd_{prefix}_should_dispatch_sync_on_tables_unavailable` filter
35
+
-**Hook Integration:** As of version 0.0.7, uses `action_scheduler_init` hook instead of `init` to ensure Action Scheduler is ready.
30
36
- You can listen for those errors above, by listening to the following actions:
31
37
-`shepherd_{prefix}_task_scheduling_failed`
32
38
-`shepherd_{prefix}_task_already_exists`
@@ -106,6 +112,8 @@ Service provider for dependency injection and initialization.
106
112
107
113
Initializes Shepherd and registers all components.
108
114
115
+
-**Since version 0.0.7:** The Regulator is only registered after tables are successfully created/updated via the `shepherd_{prefix}_tables_registered` action.
Copy file name to clipboardExpand all lines: docs/configuration.md
+13Lines changed: 13 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,10 +115,22 @@ The tasks table is created automatically when you call `Provider::register()`.
115
115
116
116
The logs table is only created if you're using the `DB_Logger`. When using the default `ActionScheduler_DB_Logger`, logs are stored in Action Scheduler's existing `actionscheduler_logs` table.
117
117
118
+
**Since version 0.0.7:**
119
+
120
+
- Tables are created/updated before the Regulator is initialized
121
+
- The `shepherd_{prefix}_tables_registered` action is fired upon successful table registration
122
+
- The `shepherd_{prefix}_tables_error` action is fired if table creation fails
123
+
- The Regulator will only be registered after tables are successfully created
124
+
118
125
## Action Scheduler Configuration
119
126
120
127
Shepherd uses Action Scheduler for task scheduling. You can configure Action Scheduler settings separately:
121
128
129
+
**Since version 0.0.7:**
130
+
131
+
- Shepherd now uses the `action_scheduler_init` hook to ensure Action Scheduler is ready before dispatching tasks
132
+
- Tasks dispatched before Action Scheduler initialization are automatically queued and dispatched once it's ready
133
+
122
134
### Custom Action Scheduler Tables
123
135
124
136
Action Scheduler uses its own tables. If you need custom table names, configure Action Scheduler before loading Shepherd.
2.**Use Consistent Prefixes**: Keep your hook prefix consistent across your application
162
174
3.**Container Singleton**: Always register Provider as a singleton
163
175
4.**Check Registration**: If you are not sure whether Shepherd is registered, you can check it using `Provider::is_registered()` before accessing Shepherd
176
+
5.**Table Initialization** (since 0.0.7): Listen to `shepherd_{prefix}_tables_registered` if you need to perform actions after tables are ready
if ( ! has_action( "shepherd_{$prefix}_tables_error" ) ) {
88
+
_doing_it_wrong( __METHOD__, esc_html__( 'Your software should be handling the case where Shepherd tables are not registered successfully and notify your end users about it.', 'stellarwp-shepherd' ), '0.0.7' );
0 commit comments