Config.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. namespace EasySwoole\Task;
  3. use EasySwoole\Spl\SplBean;
  4. use EasySwoole\Task\AbstractInterface\TaskQueueInterface;
  5. class Config extends SplBean
  6. {
  7. protected $tempDir;
  8. protected $workerNum = 3;
  9. protected $serverName = 'EasySwoole';
  10. protected $maxRunningNum = 128;
  11. protected $maxPackageSize = 1024 * 1024 * 2;//2M
  12. /**
  13. * @var float
  14. */
  15. protected $timeout = 5.0;
  16. protected $onException;
  17. /**
  18. * @var TaskQueueInterface
  19. */
  20. protected $taskQueue;
  21. /**
  22. * @return float|int
  23. */
  24. public function getMaxPackageSize()
  25. {
  26. return $this->maxPackageSize;
  27. }
  28. /**
  29. * @param float|int $maxPackageSize
  30. */
  31. public function setMaxPackageSize($maxPackageSize): void
  32. {
  33. $this->maxPackageSize = $maxPackageSize;
  34. }
  35. /**
  36. * @return mixed
  37. */
  38. public function getTempDir()
  39. {
  40. return $this->tempDir;
  41. }
  42. /**
  43. * @param mixed $tempDir
  44. */
  45. public function setTempDir($tempDir): void
  46. {
  47. $this->tempDir = $tempDir;
  48. }
  49. /**
  50. * @return int
  51. */
  52. public function getWorkerNum(): int
  53. {
  54. return $this->workerNum;
  55. }
  56. /**
  57. * @param int $workerNum
  58. */
  59. public function setWorkerNum(int $workerNum): void
  60. {
  61. $this->workerNum = $workerNum;
  62. }
  63. /**
  64. * @return string
  65. */
  66. public function getServerName(): string
  67. {
  68. return $this->serverName;
  69. }
  70. /**
  71. * @param string $serverName
  72. */
  73. public function setServerName(string $serverName): void
  74. {
  75. $this->serverName = $serverName;
  76. }
  77. /**
  78. * @return int
  79. */
  80. public function getMaxRunningNum(): int
  81. {
  82. return $this->maxRunningNum;
  83. }
  84. /**
  85. * @param int $maxRunningNum
  86. */
  87. public function setMaxRunningNum(int $maxRunningNum): void
  88. {
  89. $this->maxRunningNum = $maxRunningNum;
  90. }
  91. /**
  92. * @return float
  93. */
  94. public function getTimeout(): float
  95. {
  96. return $this->timeout;
  97. }
  98. /**
  99. * @param float $timeout
  100. */
  101. public function setTimeout(float $timeout): void
  102. {
  103. $this->timeout = $timeout;
  104. }
  105. /**
  106. * @return mixed
  107. */
  108. public function getOnException()
  109. {
  110. return $this->onException;
  111. }
  112. /**
  113. * @param mixed $onException
  114. */
  115. public function setOnException($onException): void
  116. {
  117. $this->onException = $onException;
  118. }
  119. /**
  120. * @return TaskQueueInterface
  121. */
  122. public function getTaskQueue(): ?TaskQueueInterface
  123. {
  124. return $this->taskQueue;
  125. }
  126. /**
  127. * @param TaskQueueInterface $taskQueue
  128. */
  129. public function setTaskQueue(TaskQueueInterface $taskQueue): void
  130. {
  131. $this->taskQueue = $taskQueue;
  132. }
  133. protected function initialize(): void
  134. {
  135. if(empty($this->tempDir)){
  136. $this->tempDir = getcwd();
  137. }
  138. }
  139. }