BulkEnrollmentJobRunner
\Benecaster\Membership\BulkEnrollmentJobRunner
Asynchronous orchestrator around BulkEnrollmentProcessor. The REST endpoint queues a job via start(); a single WP-Cron event then runs the entire batch in one tick, streaming progress through the processor’s row callback into a wp_option the React polling loop reads via get_progress(). Progress is stored in options, not transients, so it survives long imports the same way FeedBulkImporter does. Only one active job per show is tracked (benecaster_enroll_active_job).
Constructor Dependencies
| Type | Description |
|---|---|
BulkEnrollmentProcessor |
Runs the synchronous enroll() call for the queued job. |
Methods
| Method | Visibility | Since | Description |
|---|---|---|---|
start( int $show_id, string $tier_slug, array $addresses, string $billing_interval = 'monthly', string $token_type = 'subscriber' ): string |
Public | — | Queues a job: filters blank/whitespace addresses (so the reported total matches what will actually be processed), writes the job and an initial progress record to wp_options under a random job ID, records the show's active job ID, and schedules a single WP-Cron event to run it. $token_type is carried on both the job and its progress, so the status poll can say "adding followers" after a page reload. A job with no stored $token_type reads as 'subscriber'. Returns the generated job ID. |
get_progress( string $job_id ): ?array |
Public | — | Reads the job's progress record: token_type, total, processed, enrolled, already_enrolled, skipped, errors, status ('running' or 'complete'), and rows (the per-row outcome list so far). Returns null if the job ID is unknown. |
get_active_job_id( int $show_id ): string |
Public | — | The currently-running job's ID for this show, or an empty string if none. |
process_job( string $job_id ): void |
Public | — | The WP-Cron callback — not intended to be called directly. Loads the queued job, runs BulkEnrollmentProcessor::enroll() with a row callback that flushes progress to the option after every row, then marks the job complete. The processor fires benecaster_bulk_enrollment_complete itself when it finishes — except the refusal case below, where it does not. Catches BulkEnrollBridgeNotBuiltin: a subscriber job whose show was switched off the built-in membership between the REST endpoint queuing the job and this cron tick running it still completes (status: complete), but every address is reported as an 'error' row with message 'bridge_not_builtin', errors equals the total address count, and nothing was created. |
Constants
| Name | Value | Description |
|---|---|---|
CRON_HOOK |
'benecaster_run_bulk_enrollment' |
The WP-Cron action start() schedules and register() hooks process_job() to. |
Notes
Registered automatically on plugin boot via register(). Progress is readable via GET /shows/{show_id}/subscribers/bulk-enroll/status at a 2-second poll interval. A refused subscriber job (BulkEnrollBridgeNotBuiltin, caught in process_job()) still reaches status: complete with every row an error — see process_job() above.