-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.cronJobs.php
60 lines (53 loc) · 2.6 KB
/
functions.cronJobs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
//CRON JOB MANAGEMENT FUNCTIONS
function logCron($msg) {
global $thisCommRun,$rollingCronLogUpdates,$cronJobID,$echoDebug, $ignoreCronLog, $logCommLogs;
}
function logCronORI($msg) {
global $thisCommRun,$rollingCronLogUpdates,$cronJobID,$echoDebug, $ignoreCronLog, $logCommLogs;
$msg = "\n\n".time().' :: '.$msg.'';
//if($logCommLogs && $thisCommRun != '') insertCommLog($msg, $thisCommRun);
$query = "UPDATE cronJobs SET jobLog = CONCAT(jobLog, ".quote_smart($msg)."), memoryUsage = ".quote_smart(getMemoryUsage())." WHERE id = ".quote_smart($cronJobID)."";
if($rollingCronLogUpdates === TRUE && $cronJobID != '') mysql_query($query) or die(mysql_error());
if($ignoreCronLog !== TRUE) $GLOBALS['cronLog'] .= $msg;
if($echoDebug) echo str_replace("\n","<BR>\n",$msg).'<BR>'."";
}
function initCronJob($jobName) {
$thisCronJob = $jobName;
$thisJobNumber = rand(0,getrandmax());
$GLOBALS['thisJobNumber'] = $thisJobNumber;
$GLOBALS['thisCronJob'] = $thisCronJob;
$GLOBALS['jobName'] = $thisCronJob;
$GLOBALS['scriptStart'] = time();
$GLOBALS['startTimestamp'] = $GLOBALS['scriptStart'];
$GLOBALS['cronLog'] = '';
$GLOBALS['thisRun'] = 0;
mysql_query("INSERT INTO cronJobs (jobName, jobNumber, jobStarted, jobLog, jobActive) VALUES (".quote_smart($thisCronJob).", ".quote_smart($thisJobNumber).", NOW(), ".quote_smart("Job Started").", 'yes')");
$cronJobID = mysql_insert_id();
$GLOBALS['cronJobID'] = $cronJobID;
return $cronJobID;
}
function setCronJobLoopNumber($loopNumber) {
global $jobName;
$query = mysql_query("UPDATE cronJobs SET jobLoopNumber = ".quote_smart($loopNumber)." WHERE jobName = ".quote_smart($jobName)." AND jobNumber = ".quote_smart($GLOBALS['cronJobID'])."");
}
function isCronJobActive($reportInactive = TRUE) {
global $thisCronJob, $cronJobID;
$activeJobs = getValue("SELECT COUNT(id) FROM cronJobs WHERE jobName = ".quote_smart($thisCronJob)." AND jobActive = 'yes'");
$GLOBALS['activeJobs'] = $activeJobs;
if($activeJobs > 1) { //GREATER THAN 1 BECAUSE WE ALREADY HAVE THIS ONE ACTIVE THAT WE ARE LOOKING AT
return TRUE;
} else {
return FALSE;
}
}
function endCronJob($message = '') {
global $thisCronJob, $cronJobID, $activeJobs, $cronLog, $scriptStart, $queriesRun;
$scriptEnd = time();
if($message != '') logCron($message);
logCron('<h1>Script Took '.($scriptEnd-$scriptStart).' second(s)</h1>');
logCron("Cron (".$thisCronJob.") Finished at ".date("M d Y g:i:as")."\nRan ".$queriesRun." queries.\n\n");
mysql_query("UPDATE cronJobs SET jobActive = 'no' WHERE id = ".quote_smart($cronJobID)."");
exit();
}
?>