queue = $queue ?? new WorkflowQueue(); } /** * Register cron schedule and hook. * * @return void */ public function register(): void { /* add_filter( 'cron_schedules', array( $this, 'addCronSchedule' ) ); add_action( self::CRON_HOOK, array( $this, 'processWorkflowQueue' ) ); if ( ! wp_next_scheduled( self::CRON_HOOK ) ) { wp_schedule_event( time(), self::CRON_INTERVAL, self::CRON_HOOK ); } */ } /** * Add custom cron interval. * * @param array> $schedules Cron schedules. * @return array> */ public function addCronSchedule( array $schedules ): array { $schedules[ self::CRON_INTERVAL ] = array( 'interval' => 60, 'display' => __( 'Every Minute', 'afroit-messaging-workflows' ), ); return $schedules; } /** * Process pending workflow jobs. * * @return void */ public function processWorkflowQueue(): void { $this->queue->processPending( 10 ); } }