Skip to content

Commit

Permalink
Update batch size and manage cron events
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelkey-support committed Nov 27, 2023
1 parent 99f5274 commit 043af63
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions core/includes/classes/PixelkeyAlgoliaHelpers.php
Expand Up @@ -203,7 +203,7 @@ function process_additional_settings()
];
}
// Sanitize the input
$batch_size = min(1000, max(50, intval($_POST['pixelkey_algolia_batch_size'])));
$batch_size = min(100000, max(50, intval($_POST['pixelkey_algolia_batch_size'])));
$batch_interval = min(10, max(1, intval($_POST['pixelkey_algolia_batch_interval'])));
$cron_interval = sanitize_text_field($_POST['pixelkey_algolia_cron_interval']);

Expand All @@ -218,11 +218,11 @@ function process_additional_settings()

if ($is_updated) {
$cron_event = PixelkeyAlgolia()->settings->get_event_name();
if (wp_next_scheduled($cron_event)) {
wp_clear_scheduled_hook($cron_event);
}
wp_schedule_event(time() + 5 * MINUTE_IN_SECONDS, $cron_interval, $cron_event);
$daisyChainCronEvent = PixelkeyAlgolia()->settings->get_daisyChainEvent();
$this->manage_cron_event($cron_event, $cron_interval, true);
$this->manage_cron_event($daisyChainCronEvent, $cron_interval, false);
}

$response['classes'] = 'updated';
$response['message'] = 'Data saved successfully.';
} catch (\Exception $e) {
Expand Down Expand Up @@ -252,4 +252,18 @@ public function add_pixelkey_algolia_cron_interval($schedules)

return $schedules;
}

/**
* Manage cron event
* @param string $event_name The name of the event
* @param string $interval The interval of the event
* @return void
*/
public function manage_cron_event($event_name, $interval, $re_schedule = true)
{
if (wp_next_scheduled($event_name)) {
wp_clear_scheduled_hook($event_name);
}
$re_schedule ? wp_schedule_event(time() + 5 * MINUTE_IN_SECONDS, $interval, $event_name) : null;
}
}

0 comments on commit 043af63

Please sign in to comment.