0) { $nextRunStr = null; // Paused until task completion } elseif ($st === 'interval' && $interval > 0) { $nextRun = new DateTime("+{$interval} minutes", new DateTimeZone('UTC')); $nextRunStr = $nextRun->format('Y-m-d H:i:s'); } else { $nextRun = calculateNextRun($task['CronExpression']); $nextRunStr = $nextRun->format('Y-m-d H:i:s'); } queryTimed(" UPDATE ScheduledTaskDefinitions SET LastRunOn = NOW(), NextRunOn = ? WHERE ID = ? ", [$nextRunStr, $task['ScheduledTaskID']]); $createdTasks[] = [ 'ScheduledTaskID' => (int) $task['ScheduledTaskID'], 'TaskID' => $newTaskID, 'BusinessID' => (int) $task['BusinessID'], 'Title' => $task['Title'], ]; } jsonResponse([ 'OK' => true, 'MESSAGE' => 'Processed ' . count($createdTasks) . ' scheduled task(s)', 'CREATED_TASKS' => $createdTasks, 'CHECKED_COUNT' => count($dueTasks), 'RAN_AT' => gmdate('Y-m-d H:i:s'), ]); } catch (Exception $e) { jsonResponse(['OK' => false, 'ERROR' => 'server_error', 'MESSAGE' => $e->getMessage()]); }