MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/groups_cafsindia_com/application/libraries/CronRunner.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');

class CronRunner
{
 private $CI;

 public function __construct()
 {
    $this->CI =& get_instance();
 }

 private function calculateNextRun($obj)
 {
    return (time() + $obj->interval_sec);
 }

 public function run(){
   $query = $this->CI->db->where('is_active', 1)->where('now() >= next_run_at OR next_run_at IS NULL', '', false)->from('cron')->get();
   if ($query->num_rows() > 0) {
     $env = getenv('CI_ENV');
       foreach ($query->result() as $row) {
         $cmd = "export CI_ENV={$env} && {$row->command}";
         $this->CI->db->set('next_run_at', 'FROM_UNIXTIME('.$this->calculateNextRun($row).')', false)->where('id', $row->id)->update('cron');
         $output = shell_exec($cmd);
         $this->CI->db->set('last_run_at', 'now()', false)->where('id', $row->id)->update('cron');
       }
    } 
  }
}