--- phase: 06-email-notifications plan: 02 type: execute depends_on: [] files_modified: [vendor/action-scheduler/, includes/class-scheduler.php, includes/class-ddhh-job-manager.php, ddhh-job-manager.php] --- Integrate Action Scheduler library for async background job processing to enable non-blocking bulk email sends. Purpose: Prevent timeouts when sending emails to many mentors by processing email batches asynchronously in the background using WordPress's job queue system. Output: Action Scheduler library loaded, scheduler helper class for managing async actions, ready for email batch processing in Phase 06-03. ~/.claude/get-shit-done/workflows/execute-plan.md ./summary.md @.planning/PROJECT.md @.planning/ROADMAP.md @.planning/STATE.md # Prior work this plan builds on: @.planning/phases/03-job-management-core/03-03-SUMMARY.md **Tech stack available:** Action Scheduler (WooCommerce library), WordPress hooks, wp_mail **Established patterns:** - Static setup_hooks() method for class initialization (all phases) - Singleton pattern for utility classes (Phase 01-02) - German email templates with error logging (Phase 03-03, 04-02, 05-02) **Constraining decisions:** - PROJECT.md line 29: "Async email processing via WP-Cron/Action Scheduler" - ROADMAP.md Phase 6: Action Scheduler integration required for bulk email patterns - PROJECT.md line 43: "Email: WP Mail SMTP on production; disabled in Local WP dev" **Action Scheduler integration requirements** (from Context7 discovery): - Include library via require_once before plugins_loaded - Load from vendor/action-scheduler/action-scheduler.php - Register callbacks with add_action() for scheduled hooks - Use as_enqueue_async_action() for ASAP background processing - Use unique flag to prevent duplicate actions - Group actions logically (e.g., 'email-notifications') Task 1: Download and include Action Scheduler library vendor/action-scheduler/, ddhh-job-manager.php Download Action Scheduler library (https://github.com/woocommerce/action-scheduler/releases) and place in vendor/action-scheduler/ directory. Use latest stable release (3.x). Include library in main plugin file ddhh-job-manager.php by adding require_once( plugin_dir_path( __FILE__ ) . 'vendor/action-scheduler/action-scheduler.php' ) BEFORE any other includes and class initializations (must load early for proper initialization). Add comment explaining why it loads first. Verify action-scheduler.php exists after download. Do NOT use Composer for this - manual download and include following WordPress plugin patterns. The library will auto-initialize itself when required. Check vendor/action-scheduler/ directory exists with action-scheduler.php file. Verify require_once added to main plugin file before other includes. Confirm no PHP errors on plugin activation (action scheduler loaded successfully). Action Scheduler library downloaded to vendor/action-scheduler/, included in main plugin file before other code, library successfully initialized Task 2: Create scheduler helper class for email batch actions includes/class-scheduler.php, includes/class-ddhh-job-manager.php Create includes/class-scheduler.php with class DDHH_JM_Scheduler. Add static method setup_hooks() (empty for now - Phase 06-03 will register callbacks). Add static method schedule_mentor_notification_batch() that takes array of user IDs and job post ID as parameters. Method chunks user IDs into batches of 50 (to avoid email provider limits and timeouts). For each batch, call as_enqueue_async_action() with hook 'ddhh_jm_send_mentor_notification_batch', args array containing batch user IDs and job ID, group 'email-notifications', unique flag true (prevent duplicates), priority 10. Return count of batches scheduled. Add error_log for debugging. Initialize class in includes/class-ddhh-job-manager.php by calling DDHH_JM_Scheduler::setup_hooks() in init_hooks(). Add require_once in main plugin file following established pattern (after Action Scheduler include). Check includes/class-scheduler.php exists with DDHH_JM_Scheduler class. Verify schedule_mentor_notification_batch() method chunks users into batches of 50. Confirm as_enqueue_async_action() called for each batch with correct parameters. Verify class initialized in main plugin. Scheduler helper class created, batch scheduling method exists with 50-user chunks, async actions enqueued via Action Scheduler, class initialized in plugin Before declaring plan complete: - [ ] Action Scheduler library exists in vendor/action-scheduler/ - [ ] Library loaded in main plugin file before other includes - [ ] Scheduler helper class created in includes/class-scheduler.php - [ ] Batch scheduling method chunks users appropriately - [ ] Action Scheduler functions available (as_enqueue_async_action works) - [ ] No PHP errors on plugin activation - Action Scheduler library downloaded and included in plugin - Library loads without errors before other plugin code - Scheduler helper class provides batch scheduling API - Email batches limited to 50 recipients per async action - Async actions properly enqueued with unique flag and grouping - Infrastructure ready for Phase 06-03 email processing After completion, create `.planning/phases/06-email-notifications/06-02-SUMMARY.md`: # Phase 6 Plan 2: Action Scheduler Integration Summary **[Substantive one-liner - what shipped, not "phase complete"]** ## Accomplishments - [Key outcome 1] - [Key outcome 2] ## Files Created/Modified - `vendor/action-scheduler/` - Description - `includes/class-scheduler.php` - Description - `includes/class-ddhh-job-manager.php` - Description - `ddhh-job-manager.php` - Description ## Decisions Made [Key decisions and rationale, or "None"] ## Issues Encountered [Problems and resolutions, or "None"] ## Next Step Ready for parallel execution with 06-01 (Mentor opt-in). Both 06-01 and 06-02 are independent and can run concurrently.