Skip to content

Commit

Permalink
fixes: cron基类 缓存文件地址无法自定义; try捕获范围增加
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanyanwow authored Nov 20, 2020
1 parent 0a8ea33 commit fc20af9
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/siam/AbstractInterface/CronBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ abstract class CronBase
*/
public function __construct()
{
static::$runtimePath = dirname(__FILE__);
if(empty(static::$runtimePath)) static::$runtimePath = dirname(__FILE__);
// 判断是否为单一任务 是的话停止运行
$lockName = static::$runtimePath.DIRECTORY_SEPARATOR.md5($this->rule()).".txt";
$lockName = static::$runtimePath.DIRECTORY_SEPARATOR.$this->rule().".txt";
if ( static::$singleCron && file_exists($lockName) ){
throw new \Exception($this->rule() . " is single cron job");
}
Expand All @@ -42,9 +42,8 @@ abstract function rule();
* @throws \Throwable
*/
public function run(){
$data = $this->before();

try{
$data = $this->before();
$res = $this->do($data);
}catch (\Throwable $throwable){
$this->clearClock();
Expand Down Expand Up @@ -74,9 +73,9 @@ abstract function after($res = true);

private function clearClock()
{
$lockName = static::$runtimePath.DIRECTORY_SEPARATOR.md5($this->rule()).".txt";
$lockName = static::$runtimePath.DIRECTORY_SEPARATOR.$this->rule().".txt";
if (file_exists($lockName)){
unlink($lockName);
}
}
}
}

0 comments on commit fc20af9

Please sign in to comment.