executeJob($job_id); } catch (\Exception $e) { Logger::error('automation', 'Job execution failed', ['job_id' => (int) $job_id, 'error' => $e->getMessage()]); try { $job_manager = new AutomationJobManager(); $job_manager->updateJobStatus($job_id, 'failed', $e->getMessage(), AutomationJob::TICK_STATUSES); } catch (\Exception $update_error) { Logger::error('automation', 'Job status update failed', ['job_id' => (int) $job_id, 'error' => $update_error->getMessage()]); } } } /** * Register the legacy per-job execution hook for a specific job * * Legacy: goes after the next release with the per-job names. * * @param int $job_id Job ID */ public static function register_job_hook($job_id) { $hook_name = JobRunHook::LEGACY_PREFIX . $job_id; if (!has_action($hook_name)) { add_action($hook_name, [self::class, 'execute_job_callback'], 10, 1); } } /** * Unregister job execution hook for a specific job * * @param int $job_id Job ID */ public static function unregister_job_hook($job_id) { $hook_name = JobRunHook::LEGACY_PREFIX . $job_id; remove_action($hook_name, [self::class, 'execute_job_callback'], 10); } /** * Register catch-all hook for job execution * * The hook every job run is scheduled on. It makes no database query. */ public static function register_catch_all_hook() { add_action(JobRunHook::HOOK, [self::class, 'execute_job_callback'], 10, 1); } }