<?php

add_filter( 'cron_schedules', 'sage_ai_run_queue_interval' );

function sage_ai_run_queue_interval( $schedules ) {

	$schedules['two_minutes'] = array(
		'interval' => 120,
		'display'  => esc_html__( 'Every Two Minutes' ),
	);
	return $schedules;
}



add_action( 'init', 'sage_ai_schedule_queue_cron' );

function sage_ai_schedule_queue_cron() {
	if ( ! wp_next_scheduled( 'sage_ai_queue_cron' ) ) {
		wp_schedule_event( time(), 'two_minutes', 'sage_ai_queue_cron' );
	}
}


add_action( 'sage_ai_queue_cron', 'sage_ai_queue_cron_callback' );

function sage_ai_queue_cron_callback() {

	$bulk_queue_processor = get_option( 'sage_ai_bulk_job_queue_processor' );

	if ( $bulk_queue_processor['status'] === 'running' ) {
		return;
	}

	sage_ai_run_bulk_queue();
}
