-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c942d33
commit 119f570
Showing
27 changed files
with
639 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,26 +43,38 @@ public function addCron($file, $method, $dayOfWeek, $records = []) { | |
if (!empty($records)) { | ||
$cronjob->setRecords($records); | ||
} | ||
// Application::log("Has day of week $dayOfWeek and timestamp for ".date("Y-m-d", $dateTs)); | ||
if ($this->isDebug) { | ||
Application::log("Has day of week $dayOfWeek and timestamp for ".date("Y-m-d", $dateTs)); | ||
} | ||
if (in_array($dayOfWeek, $possibleDays)) { | ||
# Weekday | ||
if (!isset($this->crons[$dayOfWeek])) { | ||
$this->crons[$dayOfWeek] = []; | ||
// Application::log("Reset cron list for $dayOfWeek"); | ||
if ($this->isDebug) { | ||
Application::log("Reset cron list for $dayOfWeek"); | ||
} | ||
} | ||
$this->crons[$dayOfWeek][] = $cronjob; | ||
// Application::log("Assigned cron for $dayOfWeek"); | ||
if ($this->isDebug) { | ||
Application::log("Assigned cron for $dayOfWeek"); | ||
} | ||
} else if ($dateTs) { | ||
# Y-M-D | ||
$date = date(self::getDateFormat(), $dateTs); | ||
if (!isset($this->crons[$date])) { | ||
$this->crons[$date] = []; | ||
// Application::log("Reset cron list for $date"); | ||
if ($this->isDebug) { | ||
Application::log("Reset cron list for $date"); | ||
} | ||
} | ||
$this->crons[$date][] = $cronjob; | ||
// Application::log("Assigned cron for $date"); | ||
if ($this->isDebug) { | ||
Application::log("Assigned cron for $date"); | ||
} | ||
} | ||
// Application::log("Added cron $method: ".$this->getNumberOfCrons()." total crons now"); | ||
if ($this->isDebug) { | ||
Application::log("Added cron $method: ".$this->getNumberOfCrons()." total crons now"); | ||
} | ||
} | ||
|
||
private static function getDaysOfWeek() { | ||
|
@@ -138,13 +150,15 @@ public function run($adminEmail = "", $tokenName = "", $additionalEmailText = "" | |
$records = $recordsToRun; | ||
} | ||
} | ||
Application::log("Running ".$cronjob->getTitle()); | ||
Application::log("Running ".$cronjob->getTitle()." with ".count($records)." records"); | ||
$run[$cronjob->getTitle()] = array("text" => "Attempted", "ts" => self::getTimestamp()); | ||
try { | ||
if (!$this->token || !$this->server) { | ||
throw new \Exception("Could not pass token '".$this->token."' or server '".$this->server."' to cron job"); | ||
} | ||
$cronjob->run($this->token, $this->server, $this->pid, $records); | ||
if (!$this->isDebug) { | ||
$cronjob->run($this->token, $this->server, $this->pid, $records); | ||
} | ||
$run[$cronjob->getTitle()] = array("text" => "Succeeded", "ts" => self::getTimestamp()); | ||
} catch(\Throwable $e) { | ||
$this->handle($e, $adminEmail, $cronjob); | ||
|
@@ -153,6 +167,13 @@ public function run($adminEmail = "", $tokenName = "", $additionalEmailText = "" | |
} | ||
} | ||
if (count($toRun) > 0) { | ||
if ($this->isDebug) { | ||
Application::log("Attempting to save current date"); | ||
Application::saveCurrentDate("Test", $this->pid); | ||
Application::removeCurrentDate("Test", $this->pid); | ||
Application::log("Done attempting to save current date"); | ||
} | ||
|
||
$text = $tokenName." ".$this->server."<br><br>"; | ||
foreach ($run as $title => $mssgAry) { | ||
$mssg = $mssgAry['text']; | ||
|
@@ -168,12 +189,18 @@ public function run($adminEmail = "", $tokenName = "", $additionalEmailText = "" | |
} | ||
if (!class_exists("\REDCap") || !method_exists("\REDCap", "email")) { | ||
throw new \Exception("Could not instantiate REDCap class!"); | ||
} | ||
Application::log("Sending ".Application::getProgramName()." email for pid ".$this->pid." to $adminEmail"); | ||
\REDCap::email($adminEmail, "[email protected]", Application::getProgramName()." Cron Report", $text); | ||
} | ||
if (!$this->isDebug) { | ||
Application::log("Sending ".Application::getProgramName()." email for pid ".$this->pid." to $adminEmail"); | ||
\REDCap::email($adminEmail, "[email protected]", Application::getProgramName()." Cron Report", $text); | ||
} | ||
} | ||
} | ||
|
||
public function setDebug($isDebug) { | ||
$this->isDebug = $isDebug; | ||
} | ||
|
||
public function handle($e, $adminEmail, $cronjob) { | ||
Application::log("Exception ".json_encode($e)); | ||
if (!class_exists("\REDCap") || !method_exists("\REDCap", "email")) { | ||
|
@@ -200,6 +227,7 @@ public function handle($e, $adminEmail, $cronjob) { | |
private $sendErrorLogs; | ||
private static $lastAdminEmail; | ||
private static $lastSendErrorLogs; | ||
private $isDebug = FALSE; | ||
} | ||
|
||
class CronJob { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.