12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace task;
- class task_wrapper
- {
- //1待处理、2处理中、3已处理、4已经取消'
- const Waiting = 1;
- const Processing = 2;
- const Handled = 3;
- const Canceled = 4;
- private $mRecord;
- public function __construct($item)
- {
- $this->mRecord = $item;
- }
- public function waiting() : bool {
- return $this->mRecord['state'] == self::Waiting;
- }
- public function processing() : bool {
- return $this->mRecord['state'] == self::Processing;
- }
- public function completed() : bool
- {
- return $this->mRecord['state'] == self::Handled;
- }
- public function success() : bool {
- return $this->mRecord['result_state'] == 1;
- }
- public function task_id()
- {
- return $this->mRecord['task_id'];
- }
- public function result()
- {
- if($this->success()) {
- return unserialize($this->mRecord['result']);
- } else {
- return [];
- }
- }
- public function add_time() : int {
- return intval($this->mRecord['add_time']) ?? time();
- }
- public function act_time() : int {
- return intval($this->mRecord['act_time']) ?? time();
- }
- public function fini_time() : int {
- return intval($this->mRecord['finish_time']) ?? time();
- }
- public static function CreateTask($data)
- {
- return new task_wrapper($data);
- }
- }
|