fetch_and_update_tests(); } /** * Remove jobs. */ public static function remove_jobs() { wp_clear_scheduled_hook( 'vrts_connection_check_cron' ); wp_clear_scheduled_hook( 'vrts_fetch_updates_cron' ); } /** * Fetch test updates. * * @param int $test_id Test id. * @param int $try_number Try number. */ public function fetch_test_updates( $test_id, $try_number = 1 ) { $test = Test::get_item( $test_id ); if ( empty( $test ) || empty( $test->base_screenshot_date ) ) { $service = new Test_Service(); $service->fetch_and_update_tests(); if ( $try_number < $this->max_tries ) { $next_execution = time() + $this->initial_wait * $this->wait_multiplicator * $try_number; wp_schedule_single_event( $next_execution, 'vrts_fetch_test_updates', [ $test_id, $try_number + 1 ] ); } } } /** * Fetch test run updates. * * @param int $test_run_id Test run id. * @param int $try_number Try number. */ public function fetch_test_run_updates( $test_run_id, $try_number = 1 ) { $test_run = Test_Run::get_item( $test_run_id ); if ( empty( $test_run ) || empty( $test_run->finished_at ) ) { $service = new Test_Run_Service(); $service->fetch_and_update_test_runs(); if ( $try_number < $this->max_tries ) { $next_execution = time() + $this->initial_wait * $this->wait_multiplicator * $try_number; wp_schedule_single_event( $next_execution, 'vrts_fetch_test_run_updates', [ $test_run_id, $try_number + 1 ] ); } } } /** * Schedule initial fetch test updates. * * @param int $test_id Test id. */ public static function schedule_initial_fetch_test_updates( $test_id ) { wp_schedule_single_event( time(), 'vrts_fetch_test_updates', [ $test_id, 1 ] ); } /** * Schedule initial fetch test run updates. * * @param int $test_run_id Test run id. */ public static function schedule_initial_fetch_test_run_updates( $test_run_id ) { wp_schedule_single_event( time(), 'vrts_fetch_test_run_updates', [ $test_run_id, 1 ] ); } }