Skip to content

Commit

Permalink
+ runAction/s with isDone check to run once
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Jul 28, 2015
1 parent 8ba99da commit e5c212f
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/goals/DefaultGoal.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@ public function isDone($action, $timestamp = null)
return false;
}

public function markDone($action)
/**
* Mark action as already done.
* @param $action action id
* @param $time microtime when action was done, false for action was not done
*/
public function markDone($action, $time = null)
{
$this->done[$action] = microtime(1);
$this->done[$action] = ($time===null || $time===true) ? microtime(1) : $time;
}

public function actionPerform()
{
if ($this->isDone('perform')) {
return;
}
Yii::trace("Started: $this->goalName");
$this->actionDeps();
$this->actionMake();
$this->markDone('perform');
$this->runActions('deps, make');
}

public function actionLoad()
Expand All @@ -104,8 +104,26 @@ public function actionSave()

public function actionMake()
{
$this->actionLoad();
$this->actionSave();
$this->runActions('load, save');
}

public function runAction($id, $params = [])
{
if ($this->isDone($id)) {
return;
}
$result = parent::runAction($id, $params);
$this->markDone($id);

return $result;
}

public function runActions($actions)
{
foreach (Helper::ksplit($actions) as $action) {
$result = $this->runAction($action);
}
return $result;
}

public function getRobo()
Expand Down

0 comments on commit e5c212f

Please sign in to comment.