diff --git a/README.md b/README.md index 099e880..46014b0 100644 --- a/README.md +++ b/README.md @@ -52,9 +52,9 @@ composer require mult1mate/cron-manager * Make sure that manager is not publicly available See also examples for [ActiveRecord](https://github.com/MUlt1mate/cron-manager/tree/master/examples/active_record), -[CodeIgniter](https://github.com/MUlt1mate/cron-manager/tree/master/examples/codeigniter) -and [Yii2](https://github.com/MUlt1mate/cron-manager/tree/master/examples/yii2_basic) - +[CodeIgniter](https://github.com/MUlt1mate/cron-manager/tree/master/examples/codeigniter), +[Yii2](https://github.com/MUlt1mate/cron-manager/tree/master/examples/yii2_basic), +[File storage](https://github.com/MUlt1mate/cron-manager/tree/master/examples/file_storage), ## Screenshots @@ -64,3 +64,7 @@ and [Yii2](https://github.com/MUlt1mate/cron-manager/tree/master/examples/yii2_b ![Import and export](https://cron.multimate.ru/img/Selection_003.png) See [Live Demo](https://cron.multimate.ru) for more! + +## Changelog + +* v1.1.0 - File storage models added \ No newline at end of file diff --git a/composer.json b/composer.json index c9d65ff..33c744b 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,12 @@ "name": "mult1mate/cron-manager", "description": "Flexible cron tasks manager for MVC-type applications", "minimum-stability": "stable", - "keywords": ["cron","crontab","tasks manager","schedule"], + "keywords": [ + "cron", + "crontab", + "tasks manager", + "schedule" + ], "homepage": "https://cron.multimate.ru", "license": "MIT", "authors": [ @@ -15,6 +20,9 @@ "php": ">=5.3.2", "mtdowling/cron-expression": "1.1.*" }, + "suggest": { + "monolog/monolog": "Allow writing log messages" + }, "require-dev": { "phpunit/phpunit": "4.*", "codeclimate/php-test-reporter": "^0.2.0" diff --git a/examples/active_record/models/TaskRun.php b/examples/active_record/models/TaskRun.php index 2493fb3..946a99f 100644 --- a/examples/active_record/models/TaskRun.php +++ b/examples/active_record/models/TaskRun.php @@ -107,11 +107,17 @@ public function setTs($ts) $this->ts = $ts; } + /** + * @return string + */ public function getOutput() { return $this->output; } + /** + * @param string $output + */ public function setOutput($output) { $this->output = $output; diff --git a/examples/file_storage/README.md b/examples/file_storage/README.md new file mode 100644 index 0000000..9d736f3 --- /dev/null +++ b/examples/file_storage/README.md @@ -0,0 +1,16 @@ +# PHP Cron tasks manager + +## File storage example + +Using this models you can store tasks information in file. +This method is **NOT** secure - data file can be modified by anyone. +Integrity is **NOT** guaranteed - new task_id calculated from the last task in file. It's not a problem usually. + +Data files store in /tmp/ folder by default. + +### Requirements + +* PHP 5.3 or above +* [monolog/monolog](https://github.com/Seldaek/monolog) + +Monolog uses to write log messages diff --git a/examples/active_record/models/TaskFile.php b/examples/file_storage/models/TaskFile.php similarity index 92% rename from examples/active_record/models/TaskFile.php rename to examples/file_storage/models/TaskFile.php index 27ab08a..afb422f 100644 --- a/examples/active_record/models/TaskFile.php +++ b/examples/file_storage/models/TaskFile.php @@ -2,6 +2,7 @@ use mult1mate\crontab\TaskInterface; /** + * Model that stores task information in file * @author mult1mate * Date: 22.02.16 * Time: 17:33 @@ -17,11 +18,13 @@ class TaskFile implements TaskInterface protected $ts_updated; /** + * Data file. Creates if not exists. * @var string */ protected static $data_file = '/tmp/crontasks'; /** + * Reads file from disk and returns array of tasks * @return array */ public static function taskFileLoad() @@ -38,7 +41,8 @@ public static function taskFileLoad() } /** - * @param $tasks + * Writes tasks into file + * @param array $tasks * @return bool */ public static function taskFileSave($tasks) @@ -70,6 +74,11 @@ public static function getAll() return self::taskFileLoad(); } + /** + * Returns array of tasks with specified ids + * @param array $task_ids array of task ids + * @return array + */ public static function find($task_ids) { if (!is_array($task_ids)) { @@ -136,7 +145,7 @@ public static function createNew() */ public function createTaskRun() { - return new TaskRun(); + return new TaskRunFile(); } /** diff --git a/examples/file_storage/models/TaskRunFile.php b/examples/file_storage/models/TaskRunFile.php new file mode 100644 index 0000000..db1c2e2 --- /dev/null +++ b/examples/file_storage/models/TaskRunFile.php @@ -0,0 +1,141 @@ +pushHandler(new RotatingFileHandler($this->logs_folder . $this->log_name)); + $task = TaskFile::taskGet($this->task_id); + if (self::RUN_STATUS_STARTED == $this->status) { + $message = 'task ' . $task->getCommand() . ' just started'; + } else { + $message = 'task ' . $task->getCommand() . ' ended with status ' . $this->status + . ', execution time ' . $this->execution_time . ', output: ' . PHP_EOL . $this->output; + } + return $logger->addNotice($message); + } + + /** + * @return int + */ + public function getTaskRunId() + { + return 0; + } + + /** + * @return int + */ + public function getTaskId() + { + return $this->task_id; + } + + /** + * @param int $task_id + */ + public function setTaskId($task_id) + { + $this->task_id = $task_id; + } + + /** + * @return string + */ + public function getStatus() + { + return $this->status; + } + + /** + * @param string $status + */ + public function setStatus($status) + { + $this->status = $status; + } + + /** + * @return int + */ + public function getExecutionTime() + { + return $this->execution_time; + } + + /** + * @param int $execution_time + */ + public function setExecutionTime($execution_time) + { + $this->execution_time = $execution_time; + } + + /** + * @return string + */ + public function getTs() + { + return $this->ts; + } + + /** + * @param string $ts + */ + public function setTs($ts) + { + $this->ts = $ts; + } + + /** + * @return string + */ + public function getOutput() + { + return $this->output; + } + + /** + * @param string $output + */ + public function setOutput($output) + { + $this->output = $output; + } +}