Scheduler not working for dynamic validation

Hi Team,

I have tried the schedulers for dynamically changing the field values based on two conditions
module > coll_otp_manager
fields > creationtime, status

the condition is

if the status field is active && creationtime is 45s less than current time(creationtime +45s)
then the action could be
status is “Expired”

for this i have created a scheduler

and i have created the logic hook in
D:\httpd-2.4.57\Apache24\htdocs\suitecrm841\public\legacy\modules\Schedulers\_AddJobsHere.php

in the _AddJobsHere.php I have defined my custom hook in the job_strings

$job_strings = array(
    0 => 'refreshJobs',
    1 => 'pollMonitoredInboxes',
    2 => 'runMassEmailCampaign',
    3 => 'pruneDatabase',
    4 => 'trimTracker',
    5 => 'pollMonitoredInboxesForBouncedCampaignEmails',
    6 => 'pollMonitoredInboxesAOP',
    7 => 'aorRunScheduledReports',
    8 => 'processAOW_Workflow',
    9 => 'sendEmailReminders',
    10 => 'cleanJobQueue',
    11 => 'removeDocumentsFromFS',
    12 => 'trimSugarFeeds',
    13 => 'syncGoogleCalendar',
    14 => 'runElasticSearchIndexerScheduler',
    **15 => 'expireOtpRecords',**
);

and my expireOtpRecords() {} =>

function expireOtpRecords() {
    $GLOBALS['log']->debug('entered into expireOtpRecords method ');

    $db = DBManagerFactory::getInstance();
    $currentDateTime = new DateTime('now', new DateTimeZone('UTC'));
    $currentDateTimeFormatted = $currentDateTime->format('Y-m-d H:i:s');

    // Add debug statement to log the current date and time
    $GLOBALS['log']->debug('Current_Date_and_Time: ' . $currentDateTimeFormatted);

    // Query to select all 'Active' OTP records that are older than 45 seconds
    $query = "SELECT id, creationtime FROM coll_otp_manager WHERE status = 'Active' AND TIMESTAMPDIFF(SECOND, creationtime, '{$currentDateTimeFormatted}') > 45";

    $result = $db->query($query);

    while ($row = $db->fetchByAssoc($result)) {
        $otpBean = BeanFactory::retrieveBean('coll_OTP_Manager', $row['id']);
        if ($otpBean) {
            // Add debug statement to log the OTP record ID being processed
            $GLOBALS['log']->debug('Processing OTP Record ID: ' . $otpBean->id);

            $otpBean->status = 'Expired';
            $otpBean->save();

            // Add debug statement to confirm the status update
            $GLOBALS['log']->debug('Status updated to Expired for OTP Record ID: ' . $otpBean->id);
        }
    }
}

and created batch files to run the SuiteCRM schedulers, run using Windows Scheduled Tasks

as mentioned in the suitecrm I have created my batch file like this

@echo off
cd /D D:\httpd-2.4.57\Apache24\htdocs\suitecrm841\public\legacy
php.exe -f cron.php

hope I’m done with all the steps, still, the task is not yet updated accordingly, what needs to be fixed and checked further? some one please help me with this!

You should first check if your cronjobs are running at all.

You can do this by looking at Admin / Schedulers go into one of the frequent (every minute) jobs, and check the “last ran successfully” field. It should be very recent, and in the correct timezone.

After you get that working, the you can start checking your own custom scheduler.

Scheduled tasks

getting this error while running the cronjobs in my suitecrm directory

Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in D:\httpd-2.4.57\Apache24\htdocs\suitecrm841\public\legacy\include\database\MysqliManager.php:321
Stack trace:
#0 D:\httpd-2.4.57\Apache24\htdocs\suitecrm841\public\legacy\include\database\DBManagerFactory.php(157): MysqliManager->connect(Array, true)
#1 D:\httpd-2.4.57\Apache24\htdocs\suitecrm841\public\legacy\include\entryPoint.php(205): DBManagerFactory::getInstance()
#2 D:\httpd-2.4.57\Apache24\htdocs\suitecrm841\public\legacy\cron.php(48): require_once('D:\\httpd-2.4.57...')
#3 {main}
  thrown in D:\httpd-2.4.57\Apache24\htdocs\suitecrm841\public\legacy\include\database\MysqliManager.php on line 321

and LAST SUCCESSFUL RUN run for all the schedulers was “never”

Is it possible that you haven’t installed the PHP mysqli modules? Or neglected to activate them?

extension=mysqli

this should be enabled in the php.ini right? I have done it. Let me know if anything needs to be done!

There is more than one php.ini

Check from the command-line, with

php -i | grep mysql

If it is not enabled for CLI PHP, use this to determine which file you should edit:

php -i | grep php.ini

Cron jobs run from CLI PHP, while the rest of SuiteCRM runs from web server PHP.

yes, now the scheduler is working fine. but I want the job to be run at regular intervals. the job runs only whenever I execute the

php.exe -f cron.php

how could I run the job for every 1 minute?

Go to edit option and set like below: :thinking:

No, you need to make Linux run your job from crontab

I’m working in Windows, from the other sources adding batch files into the task scheduler could achieve the same. but it wasn’t.

I have added these lines to the batch file

@echo off
cd /D D:\httpd-2.4.57\Apache24\htdocs\suitecrm841\public\legacy
php.exe -f cron.php

but this task is executed once and doesn’t repeat for the intervals. and I got the Last Successful run status once when it was executed last. as I mentioned in the picture