Making WordPress.org


Ignore:
Timestamp:
04/04/2017 06:02:37 AM (8 years ago)
Author:
dd32
Message:

Plugin Directory: SVN Watcher: Don't re-register cron jobs on the init hook as it's too race-condititiony under load with Cavalcade.
Instead add a cron job to check the cronjobs are registered correctly, with a single event set to re-add svn watcher jobs when we know it's going to be marked as failed.

See #2678

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-manager.php

    r5233 r5235  
    1515    public function __construct() {
    1616        // Register all the cron task handlers.
    17         add_action( 'init', array( $this, 'register_cron_tasks' ) );
     17        add_action( 'admin_init', array( $this, 'register_cron_tasks' ) );
    1818        add_filter( 'cron_schedules', array( $this, 'register_schedules' ) );
    1919
     
    2222        add_action( 'plugin_directory_svn_sync',         array( __NAMESPACE__ . '\SVN_Watcher', 'cron_trigger' ) );
    2323        add_action( 'plugin_directory_update_api_check', array( __NAMESPACE__ . '\API_Update_Updater', 'cron_trigger' ) );
     24
     25        // A cronjob to check cronjobs
     26        add_action( 'plugin_directory_check_cronjobs',   array( $this, 'register_cron_tasks' ) );
    2427
    2528        // Register the wildcard cron hook tasks.
     
    3538    public function register_schedules( $schedules ) {
    3639        $schedules['every_30s'] = array( 'interval' => 30, 'display' => 'Every 30 seconds' );
     40        $schedules['every_120s'] = array( 'interval' => 120, 'display' => 'Every 120 seconds' );
    3741
    3842        return $schedules;
     
    126130    /**
    127131     * Queue all of our cron tasks.
     132     *
     133     * The jobs are queued for 1 minutes time to avoid recurring job failures from repeating too soon.
    128134     */
    129     function register_cron_tasks() {
     135    public function register_cron_tasks() {
    130136        if ( ! wp_next_scheduled ( 'plugin_directory_meta_sync' ) ) {
    131             wp_schedule_event( time(), 'hourly', 'plugin_directory_meta_sync' );
     137            wp_schedule_event( time() + 60, 'hourly', 'plugin_directory_meta_sync' );
    132138        }
    133139        if ( ! wp_next_scheduled ( 'plugin_directory_svn_sync' ) ) {
    134             wp_schedule_event( time(), 'every_30s', 'plugin_directory_svn_sync' );
     140            wp_schedule_event( time() + 60, 'every_30s', 'plugin_directory_svn_sync' );
    135141        }
    136142        if ( ! wp_next_scheduled ( 'plugin_directory_update_api_check' ) ) {
    137             wp_schedule_event( time(), 'hourly', 'plugin_directory_update_api_check' );
     143            wp_schedule_event( time() + 60, 'hourly', 'plugin_directory_update_api_check' );
     144        }
     145        if ( ! wp_next_scheduled ( 'plugin_directory_check_cronjobs' ) ) {
     146            wp_schedule_event( time() + 60, 'every_120s', 'plugin_directory_check_cronjobs' );
    138147        }
    139148    }
     
    149158     * @return array The Cron array passed, unchanged.
    150159     */
    151     function register_colon_based_hook_handlers( $cron_array ) {
     160    public function register_colon_based_hook_handlers( $cron_array ) {
    152161        $wildcard_cron_tasks = array(
    153162            'import_plugin'      => array( __NAMESPACE__ . '\Plugin_Import', 'cron_trigger' ),
Note: See TracChangeset for help on using the changeset viewer.