Scheduler job doesn't execute my php changes

Hi,

I work with sugar pro 7.6 and I want to execute a custom job which checks the status of the contracts and does something.

I correctly setup my batch file (following the documentation instructions) for the execution of the scheduled job and the file is executed each minute.

I have created a file at this location C:\wamp\www\sugarcrm\custom\Extension\modules\Schedulers\Ext\ScheduledTasks\rinnovo_contratto.php with this lines

 

array_push($job_strings, 'rinnovo_contratto');
function rinnovo_contratto()
{
error_log("Start job",0);
$today = date("Y-m-d");
error_log("Date range start:".$today,0);
return true;
}

I have created a scheduler that execute rinnovo_contratto.php and in the detailview of the scheduler I can see a lot of execution of the job.

The problem is that, when I want to change the code in this php file and I want to test it, I can't do this. If I add some lines of codes nothing happens. I try to delete the cache, make a quick rebuild and rebuild the scheduler but nothing change.

There' s no errors in the log files that can help me to find a possible problem.

Or sugar executes the old job, or it doesn't execute the file.

Can you help me? I can't lose all this time for each update of my code.

Best regards 

Stefano

  • The file you are looking for isn't in the cache - it's in custom/modules/Schedulers/Ext/ScheduledTasks/scheduledtasks.ext.php.

    Try a repair-and-rebuild - that should fix your problem.

  • Hi,

    Adding your own recurring jobs to the Scheduler

    custom/Extension/modules/Schedulers/Ext/ScheduledTasks/rinnovo_contratto.php
    <?php
    $job_strings[] = 'rinnovo_contratto';
    function rinnovo_contratto(){
         $GLOBALS['log']->fatal('rinnovo_contratto Start job: ');
            $today = date("Y-m-d");
            $GLOBALS['log']->fatal('rinnovo_contratto Date range start: '.$today);
         // Must return true
         return true;
    }

    ?>


    custom/Extension/modules/Schedulers/Ext/Language/rinnovo_contratto.php

    <?php
    $mod_strings['LBL_RINNOVO_CONTRATTO'] = 'Rinnovo Contratto';

    ?>


    You can then do a Quick Rebuild and Repair and the job will be available for scheduling on the Scheduler section in the Admin section.
    Set Job for 1 min interval run cron write Sugar Log.

    https://developer.sugarcrm.com/2012/09/07/adding-your-own-reoccuring-jobs-to-the-scheduler/ 

    If anything change in code then again repair & rebuild and check it.

  • As Alan Apter has mention the cache file is in custom/modules/Schedulers/Ext/ScheduledTasks/scheduledtasks.ext.php. You can use $GLOBALS['log']->fatal("<any comment line>") on the cron.php and check if it is printing out in sugarcrm log file or not. Make sure the log level of SugarCRM is set to Fatal.

    http://support.sugarcrm.com/Knowledge_Base/Administration/Troubleshooting/Introduction_to_Sugar_Logging/#Viewing_the_Log 

    If the cron.php is not running, you can try to execute the same command that you have written in your batch file from CMD.

  • Thanks to all for the answers,

    I try and retry to rebuild and repair Sugar but nothing happens, this is the situation of my custom file and the file generated by sugar:

    C:\wamp\www\sugarcrm\custom\modules\Schedulers\Ext\ScheduledTasks\scheduledtasks.ext.php

    //Merged from custom/Extension/modules/Schedulers/Ext/ScheduledTasks/rinnovo_contratto.php


    array_push($job_strings, 'rinnovo_contratto');
    function rinnovo_contratto()
    {
    error_log("INIZIO: assegnamento azienda con contratto in scadenza al team rinnovi",0);

    $today = date("Y-m-d");
    $threeMonthsLater = new DateTime("+2 months");
    $threeMonthsLater->format("Y-m-d");

    error_log("Date range start:".$today,0);
    error_log("Date range end:".$threeMonthsLater,0);

    //trovo tutti i contratti firmati con data di scadenza nei prossimi due mesi
    $sugarQuery = new SugarQuery();
    $sugarQuery->select(array('id', 'name'));
    $contractBean = BeanFactory::newBean('Contracts');
    $sugarQuery->from($contractBean, array('team_security' => false));
    $sugarQuery->where()
    ->equals('status', 'Firmato')
    ->dateBetween('end_date',array($today,$threeMonthsLater));
    $result = $sugarQuery->execute();

    error_log("LUNGHEZZA RESULT: ".count($result));

    return true;
    }



    C:\wamp\www\sugarcrm\custom\modules\Schedulers\Ext\ScheduledTasks\scheduledtasks.ext.php

    <?php
    array_push($job_strings, 'rinnovo_contratto');
    function rinnovo_contratto()
    {
        $GLOBALS['log']->fatal("Controllo i contratti in scadenza nei prossimi due mesi");

        $today = date("Y-m-d");
        $threeMonthsLater = new DateTime("+2 months");
        $threeMonthsLater->format("Y-m-d");

        $GLOBALS['log']->fatal("Oggi:".$today);

        //trovo tutti i contratti firmati con data di scadenza nei prossimi due mesi
       /* $sugarQuery = new SugarQuery();
        $sugarQuery->select(array('id', 'name'));
        $contractBean = BeanFactory::newBean('Contracts');
        $sugarQuery->from($contractBean, array('team_security' => false));
        $sugarQuery->where()
            ->equals('status', 'Firmato')
            ->dateBetween('end_date',array($today,$threeMonthsLater));
        $result = $sugarQuery->execute();

        error_log("LUNGHEZZA RESULT: ".count($result));*/

        return true;
    }


    Why is the scheduledtasks.ext.php not updated?

    The job doesn't write on the sugarcrm.log but there's a sequence of this error:

    09/06/16 07:54:59 [10248][1][FATAL] Unable to get server status: Elastica\Exception\ClientException
    09/06/16 07:54:59 [10248][1][FATAL] FTS Server is down, postponing the job for full index.

    but I think that this is due to the other scheduled jobs which they fail for some reasons.

    any suggestions? Best regards

    Stefano

  • Have you already setup the scheduler from Admin->Scheduler for you custom scheduler?  Please make it run "as often as possible" by clicking on the Advance Options after selecting your job from the drop down list and make it was shown below:

  • I try this but nothing changes, the old lines of codes still remain in the scheduledtasks.ext.php file and they are executed by the scheduler. In the cmd terminal, when I try to execute the job, I find this:

    INIZIO: assegnamento azienda con contratto in scadenza al team rinnovi
    Date range start:2016-09-06
    Date range end:
    PHP Strict standards: Declaration of Contract::list_view_parse_additional_secti
    ons() should be compatible with SugarBean::list_view_parse_additional_sections(&
    $list_form) in C:\wamp\www\sugarcrm\modules\Contracts\Contract.php on line 437
    PHP Stack trace:
    PHP 1. {main}() C:\wamp\www\sugarcrm\cron.php:0
    PHP 2. SugarCronJobs->runCycle() C:\wamp\www\sugarcrm\cron.php:43
    PHP 3. SugarCronJobs->executeJob() C:\wamp\www\sugarcrm\include\SugarQueue\Sug
    arCronJobs.php:237
    PHP 4. SchedulersJob->runJob() C:\wamp\www\sugarcrm\include\SugarQueue\SugarCr
    onJobs.php:192
    PHP 5. call_user_func_array() C:\wamp\www\sugarcrm\modules\SchedulersJobs\Sche
    dulersJob.php:503
    PHP 6. rinnovo_contratto() C:\wamp\www\sugarcrm\modules\SchedulersJobs\Schedul
    ersJob.php:503
    PHP 7. BeanFactory::newBean() C:\wamp\www\sugarcrm\custom\modules\Schedulers\E
    xt\ScheduledTasks\scheduledtasks.ext.php:124
    PHP 8. BeanFactory::getBean() C:\wamp\www\sugarcrm\data\BeanFactory.php:203
    PHP 9. class_exists() C:\wamp\www\sugarcrm\data\BeanFactory.php:78
    PHP 10. SugarAutoLoader::autoload() C:\wamp\www\sugarcrm\data\BeanFactory.php:0


    Strict standards: Declaration of Contract::list_view_parse_additional_sections()
    should be compatible with SugarBean::list_view_parse_additional_sections(&$list
    _form) in C:\wamp\www\sugarcrm\modules\Contracts\Contract.php on line 437

    Call Stack:
    0.0004 244320 1. {main}() C:\wamp\www\sugarcrm\cron.php:0
    1.5374 45590288 2. SugarCronJobs->runCycle() C:\wamp\www\sugarcrm\cron.p
    hp:43
    6.3090 79992584 3. SugarCronJobs->executeJob() C:\wamp\www\sugarcrm\incl
    ude\SugarQueue\SugarCronJobs.php:237
    6.3090 79992584 4. SchedulersJob->runJob() C:\wamp\www\sugarcrm\include\
    SugarQueue\SugarCronJobs.php:192
    6.3097 80050336 5. call_user_func_array() C:\wamp\www\sugarcrm\modules\S
    chedulersJobs\SchedulersJob.php:503
    6.3097 80050656 6. rinnovo_contratto() C:\wamp\www\sugarcrm\modules\Sche
    dulersJobs\SchedulersJob.php:503
    6.3361 80091016 7. BeanFactory::newBean() C:\wamp\www\sugarcrm\custom\mo
    dules\Schedulers\Ext\ScheduledTasks\scheduledtasks.ext.php:124
    6.3361 80091016 8. BeanFactory::getBean() C:\wamp\www\sugarcrm\data\Bean
    Factory.php:203
    6.3362 80091832 9. class_exists() C:\wamp\www\sugarcrm\data\BeanFactory.
    php:78
    6.3362 80092152 10. SugarAutoLoader::autoload() C:\wamp\www\sugarcrm\data
    \BeanFactory.php:0

    LUNGHEZZA RESULT: 0

    This is the log of the execution of my job I think, and the error_log functions of my old code are correctly printed.

    There are also two errors due to the code, but the real problem is that the new code is not executed.

    If I manually change the code in the scheduledtasks.ext.php file and I update the relative file of the custom job this can be a solution to my problem or is a bad practice which can create other problems?

  • I guess the application server is not able to rewrite on custom/modules/Schedulers/Ext/ScheduledTasks/scheduledtasks.ext.php file. Please check the permissions to this particular file and try to run repair & rebuild.

  • I guess than you don't have any choice other than to update the custom/modules/Schedulers/Ext/ScheduledTasks/scheduledtasks.ext.php manually with your latest code. Even the repair and rebuild will also do the same thing. 

  • I also guess this, thanks for your help and your time

    Best regards

    Stefano