Why my custom scheduler is not running?

I'm doing a custom scheduler to do a soft delete to a table and when i upload the package to sugar it doesn't show any error but it's not running. The status is active and there's no last execution. Also, the LBL does not show in the dropdown it's just a blank space. Here's a screenshot:

Here's my code

soft_delete_wsmonitor.php which is the custom scheduler:

<?php

array_push($job_strings, 'soft_delete_wsmonitor');
function soft_delete_wsmonitor()
{
global $db;
$conn = $db->getConection();
$query = "UPDATE wsmon_wsmonitor SET deleted = 1 WHERE date_entered < DATE_SUB(NOW(), INTERVAL 3 MONTH) LIMIT 50";
try {
$conn->executeQuery($query);
}
catch (DBALException $e) {
$GLOBALS['log']->fatal($e->getMessage());
} finally {
$conn->disconnect();
}
return true;
}

es_LA.soft_delete_wsmonitor.php which is the label extension file:

<?php

$mod_strings['LBL_CUSTOM_JOB'] = 'Soft Delete WSMonitor Records';

  • The custom label must follow the job's function name:

    $mod_strings['LBL_SOFT_DELETE_WSMONITOR'] = 'Soft Delete WS Monitor';

    Make sure cron is configured in your server (On Schedule's List View it is displayed the steps to configure it).

    Try to force running it (create a php script which loads such file) and double check the returned error.

    <?php
    if (!defined('sugarEntry')) define('sugarEntry', true);

    chdir(dirname(__FILE__));
    define('ENTRY_POINT_TYPE', 'api');
    require_once('include/entryPoint.php');

    SugarMetric_Manager::getInstance()->setMetricClass('background')->setTransactionName('cron');

    if(empty($current_language)) $current_language = $sugar_config['default_language'];

    $app_list_strings = return_app_list_strings_language($current_language);
    $app_strings = return_application_language($current_language);

    global $current_user;
    $current_user = BeanFactory::newBean('Users');
    $current_user->getSystemUser();

    // allow admin to access everything
    $adminWork = new AdminWork();
    $adminWork->startAdminWork();


    include 'custom/Extension/modules/Schedulers/Ext/ScheduledTasks/{the_script}.php';

    sugar_cleanup(false);

    if(class_exists('DBManagerFactory')) {
    $db = DBManagerFactory::getInstance();
    $db->disconnect();
    }

    if(session_id()) session_destroy();

    exit(0);

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hi Itzel,

    There are a few reasons the scheduler might not be working.
    1. Your Cron Job is not configured properly on your server. Please make sure there is an entry in your crontab for running the sugar's crons.
    2. One of the schedulers failed to complete and threw an error. Sometimes sugar will not run the next scheduled jobs in line if one of the previous jobs failed. So make sure all of the jobs are exiting properly with "return true" and handle exceptions and error via sugar logger.
    3. The reason your label isn't working is because the index in your defined label doesn't match with the job name you have created. The index should be LBL_SOFT_DELETE_WSMONITOR not LBL_CUSTOM_JOB
     
    I hope this helps.