How to execute a scheduler at a random interval?

There is a scheduler, Prune Old Record Lists
https://support.sugarcrm.com/documentation/sugar_versions/13.0/serve/administration_guide/system/schedulers/#Prune_Old_Record_Lists

which executes As Often As Possible. This scheduler will execute "optimize table record_lists" every 1 minute. 

function cleanOldRecordLists() {
    global $timedate;

	$GLOBALS['log']->info('----->Scheduler fired job of type cleanOldRecordLists()');
    $delTime = time()-3600; // Nuke anything an hour old.

    $hourAgo = $timedate->asDb($timedate->getNow()->modify("-1 hour"));

    $db = DBManagerFactory::getInstance();

    $query = "DELETE FROM record_list WHERE date_modified < '".$db->quote($hourAgo)."'";
    $db->query($query,true);
    $db->optimizeTable('record_list');

	return true;

This table, record_list, is seldom populated with data, so there's little justification for running the table optimization part of the code.

  1. Is it possible to modify the function so it only optimizes if data has been deleted?

  2. Can we adjust the scheduler to run at irregular intervals in the Advanced Settings? Specifically, we want it to run once daily at a random time between 6 - 10 AM UTC.

Parents Reply Children
No Data