From e169bae61f2291688c3b3e6982420c5eff650807 Mon Sep 17 00:00:00 2001 From: Spyros Lambrinidis Date: Tue, 9 Jun 2015 12:31:03 +0300 Subject: [PATCH 1/4] add logging category to separate from default yii logs --- CronController.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/CronController.php b/CronController.php index d392234..f365e3a 100644 --- a/CronController.php +++ b/CronController.php @@ -27,6 +27,11 @@ class CronController extends Controller { */ public $logsDir = null; + /** + * @var string path for category for logging + */ + public $logsCategory = 'yii2-cronjobs'; + /** * Update or rewrite log file * False - rewrite True - update(add to end logs) @@ -214,7 +219,6 @@ protected function isWindowsOS(){ public function actionRun($args = array()){ $tags = &$args; $tags[] = 'default'; - //Getting timestamp will be used as current $time = strtotime($this->timestamp); if ($time === false) throw new CException('Bad timestamp format'); @@ -244,15 +248,16 @@ public function actionRun($args = array()){ if(!is_writable($stderr)) { $stdout = '/dev/null'; } + $this->runCommandBackground($command, $stdout, $stderr); - Yii::info('Running task ['.(++$runned).']: '.$task['command'].' '.$task['action']); + Yii::info('Running task ['.(++$runned).']: '.$task['command'].' '.$task['action'],$this->logsCategory); } } if ($runned > 0){ - Yii::info('Runned '.$runned.' task(s) at '.date('r', $time)); + Yii::info('Runned '.$runned.' task(s) at '.date('r', $time),$this->logsCategory); } else{ - Yii::info('No task on '.date('r', $time)); + Yii::info('No task on '.date('r', $time),$this->logsCategory); } } From e6985630a3165e54332bea03d01e70281a4f1843 Mon Sep 17 00:00:00 2001 From: Spyros Lambrinidis Date: Tue, 9 Jun 2015 12:59:14 +0300 Subject: [PATCH 2/4] force create output log --- CronController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CronController.php b/CronController.php index f365e3a..9d67ed6 100644 --- a/CronController.php +++ b/CronController.php @@ -240,6 +240,11 @@ public function actionRun($args = array()){ else $stdout = $this->logFileName; $stdout = $this->formatFileName($stdout, $task); + //if stdout does not exist then create the file + if (!file_exists($stdout)){ + touch($stdout); + } + if(!is_writable($stdout)) { $stdout = '/dev/null'; } From d52df1bea341f4328778f557a2da2b38f95506db Mon Sep 17 00:00:00 2001 From: Spyros Lambrinidis Date: Tue, 9 Jun 2015 17:41:32 +0300 Subject: [PATCH 3/4] fix cron-tags --- CronController.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CronController.php b/CronController.php index d392234..e3d2512 100644 --- a/CronController.php +++ b/CronController.php @@ -212,8 +212,14 @@ protected function isWindowsOS(){ * @param array $args List of run-tags to running actions (if empty, only "default" run-tag will be runned). */ public function actionRun($args = array()){ - $tags = &$args; - $tags[] = 'default'; + + //if no args enterred then use default + //else enter the string of args into the array + if (empty($args)){ + $tags[] = 'default'; + } else { + $tags[] = &$args; + } //Getting timestamp will be used as current $time = strtotime($this->timestamp); From aebd7f52d0fd52b4fa40d44d478dbb69adae85da Mon Sep 17 00:00:00 2001 From: Spyros Lambrinidis Date: Tue, 9 Jun 2015 17:49:54 +0300 Subject: [PATCH 4/4] fix cron-tags --- CronController.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/CronController.php b/CronController.php index e3d2512..0aa9284 100644 --- a/CronController.php +++ b/CronController.php @@ -213,13 +213,12 @@ protected function isWindowsOS(){ */ public function actionRun($args = array()){ - //if no args enterred then use default - //else enter the string of args into the array - if (empty($args)){ - $tags[] = 'default'; - } else { + //always run default values + $tags[] = 'default'; + //if we have specified args in input (cron-tags) insert them in array + if (!empty($args)){ $tags[] = &$args; - } + } //Getting timestamp will be used as current $time = strtotime($this->timestamp);