Skip to content

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

Open
HardeepAsrani wants to merge 1 commit into
developmentfrom
feat/as
Open

feat: use Action Scheduler for background jobs when available#172
HardeepAsrani wants to merge 1 commit 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

Copy link
Copy Markdown

Plugin build for 84e38d1 is ready 🛎️!

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.

2 participants