humanmade / Cavalcade

A better wp-cron. Horizontally scalable, works perfectly with multisite.
https://engineering.hmn.md/projects/cavalcade/
Other
515 stars 46 forks source link

Migration #39

Open Rahe opened 7 years ago

Rahe commented 7 years ago

Hello,

My question is about current big installions that will migrate to WP native cron to Calvalcade cron system. Is it possible ? I think we can

  1. remove filters of Calvacade
  2. get the events schedules
  3. re-add the filters
  4. reschedule everything through the WordPress API

but is it safe ?

Regards,

discoinfiltrator commented 6 years ago

@Rahe , what was your solution for migrating existing cron tasks to Cavalcade?

Rahe commented 6 years ago

Hello @discoinfiltrator ,

the process described on my main message, and run it site by site

archon810 commented 4 years ago

So Cavalcade doesn't include a migration of old cron events to Cavalcade tables? Really?

discoinfiltrator commented 4 years ago

@archon810 , this is a script that my company ran a couple years back to migrate our data:

remove_filter('pre_option_cron', 'HM\Cavalcade\Plugin\Connector\get_cron_array');
remove_filter('pre_update_option_cron', 'HM\Cavalcade\Plugin\Connector\update_cron_array', 10);

$crons = _get_cron_array();

$timestamp = time();
$crons['version'] = 2;
add_option('cron_' . $timestamp, $crons);
unset($crons['version']);

_set_cron_array([]);

add_filter('pre_option_cron', 'HM\Cavalcade\Plugin\Connector\get_cron_array');
add_filter('pre_update_option_cron', 'HM\Cavalcade\Plugin\Connector\update_cron_array', 10, 2);

$count = 0;
foreach ($crons as $timestamp => $cronhooks) {
    foreach ($cronhooks as $hook => $keys) {
        foreach ($keys as $k => $v) {
            if ($v['schedule'] == '' && !isset($v['interval'])) {
                $result = wp_schedule_single_event($timestamp, $hook, $v['args']);
                if ($result !== false) {
                    $count++;
                }
            }
        }
    }
}

Definitely test it out first - I haven't ran it in some time but I believe it went fine. We only migrated the single events that were previously scheduled as any recurring events would re-schedule themselves.

I can't recall exactly but I think the add_option call was just to save a backup.