Skip to content

feat: use Action Scheduler for background jobs when available - #172

Open
HardeepAsrani wants to merge 4 commits into
developmentfrom
feat/as
Open

feat: use Action Scheduler for background jobs when available#172
HardeepAsrani wants to merge 4 commits into
developmentfrom
feat/as

Conversation

@HardeepAsrani

@HardeepAsrani HardeepAsrani commented Jun 26, 2026

Copy link
Copy Markdown
Member

Summary

Routes Hyve Lite's background jobs through Action Scheduler when it is available on the site (e.g. provided by WooCommerce or another plugin), and falls back to WP-Cron when it is not. No new dependency is added and Action Scheduler is not bundled — heavier sites benefit automatically, everyone else keeps the current behaviour.

Part of Codeinwp/hyve#37.
Pro PR: https://github.com/Codeinwp/hyve/pull/206

Changes

  • New ThemeIsle\HyveLite\Scheduler helper (inc/Scheduler.php) with three static methods that detect Action Scheduler at call time via function_exists():
    • enqueue_async()as_enqueue_async_action() / wp_schedule_single_event( time(), … )
    • schedule_single()as_schedule_single_action() / wp_schedule_single_event( time() + N, … )
    • ensure_recurring()as_schedule_recurring_action() / wp_schedule_event()
    • All Action Scheduler actions use the hyve group (visible under Tools → Scheduled Actions). ensure_recurring() self-heals: when AS is present it removes any legacy WP-Cron copy and uses AS; if AS later disappears it falls back to WP-Cron.
  • Converted all scheduling call sites in DB_Table.php (process/update/delete posts + the hourly hyve_update_posts), Main.php, Qdrant_API.php (Qdrant migration) and API.php. Action handlers (add_action) are unchanged — Action Scheduler fires the same do_action().

QA / Testing

With Action Scheduler present (install + activate WooCommerce, or any plugin that ships Action Scheduler):

  1. Go to Hyve → add a knowledge base item / post so it gets queued for processing.
  2. Open Tools → Scheduled Actions and filter by the hyve group.
  3. Confirm hyve_process_post (and, after edits, hyve_update_posts) actions appear, run, and end up Complete.
  4. Confirm the processed content actually becomes searchable in the chatbot (i.e. the job did its work, not just ran).
  5. If using Qdrant: connect Qdrant and confirm a hyve_lite_migrate_data action appears and migrates existing entries.

Without Action Scheduler (deactivate WooCommerce / any AS provider):

  1. Repeat the add/edit flow above.
  2. Confirm everything still works exactly as before (content gets processed and is searchable). Jobs now run via WP-Cron — if WP Crontrol is installed you should see hyve_process_post / hyve_update_posts events scheduled there.

Switching (regression for the self-healing path):

  1. With the hourly updater already scheduled via WP-Cron, activate WooCommerce, load any admin page, then check Tools → Scheduled Actions — the recurring hyve_update_posts should now live there (and the old WP-Cron entry should be gone).

Route all background jobs (post processing, deletion, updates and Qdrant
migration) through Action Scheduler when another plugin on the site provides
it, falling back to WP-Cron otherwise. Adds a thin Scheduler helper that
detects Action Scheduler at call time, so there is no new dependency and the
existing WP-Cron behaviour is preserved when it is unavailable.
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown

Plugin build for d1e3f85 is ready 🛎️!

The as_* functions no-op with a doing_it_wrong notice before the data
store is set up on init, so ensure_recurring() running from the
DB_Table constructor cleared the WP-Cron entry without booking its
Action Scheduler replacement, losing the recurring job. Defer the
migration to action_scheduler_init and fall back to WP-Cron for
one-off jobs enqueued too early.
@HardeepAsrani

Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts on this branch.

Copilot AI and others added 2 commits July 14, 2026 09:35
Co-authored-by: HardeepAsrani <2649903+HardeepAsrani@users.noreply.github.com>
Co-authored-by: HardeepAsrani <2649903+HardeepAsrani@users.noreply.github.com>

Copilot AI commented Jul 14, 2026

Copy link
Copy Markdown

@copilot resolve the merge conflicts on this branch.

Merge conflicts have been resolved (commit fix: resolve merge conflicts with development branch in DB_Table.php). There were two conflicts in inc/DB_Table.php — both in process_post() where my branch had simple Scheduler::schedule_single() reschedule calls and development introduced the more robust handle_processing_failure() method (with error recording, backoff retries, and fatal-error detection). I kept the development logic and also updated handle_processing_failure() itself to route through Scheduler::schedule_single() so retries also benefit from Action Scheduler when available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants