task_wrapper.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace task;
  3. class task_wrapper
  4. {
  5. //1待处理、2处理中、3已处理、4已经取消'
  6. const Waiting = 1;
  7. const Processing = 2;
  8. const Handled = 3;
  9. const Canceled = 4;
  10. private $mRecord;
  11. public function __construct($item)
  12. {
  13. $this->mRecord = $item;
  14. }
  15. public function waiting() : bool {
  16. return $this->mRecord['state'] == self::Waiting;
  17. }
  18. public function processing() : bool {
  19. return $this->mRecord['state'] == self::Processing;
  20. }
  21. public function completed() : bool
  22. {
  23. return $this->mRecord['state'] == self::Handled;
  24. }
  25. public function success() : bool {
  26. return $this->mRecord['result_state'] == 1;
  27. }
  28. public function task_id()
  29. {
  30. return $this->mRecord['task_id'];
  31. }
  32. public function result()
  33. {
  34. if($this->success()) {
  35. return unserialize($this->mRecord['result']);
  36. } else {
  37. return [];
  38. }
  39. }
  40. public function add_time() : int {
  41. return intval($this->mRecord['add_time']) ?? time();
  42. }
  43. public function act_time() : int {
  44. return intval($this->mRecord['act_time']) ?? time();
  45. }
  46. public function fini_time() : int {
  47. return intval($this->mRecord['finish_time']) ?? time();
  48. }
  49. public static function CreateTask($data)
  50. {
  51. return new task_wrapper($data);
  52. }
  53. }