'scheduled', 'no_revisions' => true, 'no_spam' => true, ) ); if ( ! is_wp_error( $job ) ) { wp_schedule_single_event( time(), self::HOOK_RUN, array( $job->id, 1 ) ); } } /** * Runs one slice, then queues the next one. * * @param string $id Job id. * @param int $n Slice counter (keeps events unique). * @return void */ public static function run( $id, $n = 1 ) { $status = Shiftbox_Runner::tick( $id ); if ( empty( $status['done'] ) && empty( $status['error'] ) && empty( $status['gone'] ) && $n < 5000 ) { wp_schedule_single_event( time() + ( empty( $status['busy'] ) ? 1 : 15 ), self::HOOK_RUN, array( $id, $n + 1 ) ); } } /** * Keeps only the newest scheduled backups. * * @return void */ public static function apply_retention() { $keep = (int) Shiftbox_Settings::get( 'keep' ); $n = 0; foreach ( Shiftbox_Storage::list_backups() as $b ) { if ( false === strpos( $b['name'], '-scheduled-' ) ) { continue; } ++$n; if ( $n > $keep ) { @unlink( Shiftbox_Storage::dir() . '/' . $b['name'] ); } } } }