Improving lazy checks for stale artefacts; Adding artefacts stale check bench timings
Publish PHP Package / docker (push) Successful in 6s
Details
Publish PHP Package / docker (push) Successful in 6s
Details
This commit is contained in:
parent
c0caa504a9
commit
e5f15251d7
|
@ -87,17 +87,30 @@ class TaskmanArtefact
|
|||
|
||||
function isSourcesAffected(int $idx) : bool
|
||||
{
|
||||
return isset($this->sources_affected[$idx]) && $this->sources_affected[$idx];
|
||||
if(!isset($this->sources_affected[$idx]))
|
||||
{
|
||||
$file_changes = $this->task->getFileChanges();
|
||||
$sources = $file_changes != null ? $this->getChangedSources($idx) : $this->getSources($idx);
|
||||
$this->sources_affected[$idx] = is_stale($this->getPath(), $sources);
|
||||
}
|
||||
|
||||
return $this->sources_affected[$idx];
|
||||
}
|
||||
|
||||
function getAffectedSourcesIndices() : array
|
||||
{
|
||||
return array_keys($this->sources_affected);
|
||||
$indices = array();
|
||||
foreach($this->sources_affected as $idx => $is_affected)
|
||||
{
|
||||
if($is_affected)
|
||||
$indices[] = $idx;
|
||||
}
|
||||
return $indices;
|
||||
}
|
||||
|
||||
function isStale() : bool
|
||||
{
|
||||
return count($this->sources_affected) > 0;
|
||||
return count($this->getAffectedSourcesIndices()) > 0;
|
||||
}
|
||||
|
||||
function initSources()
|
||||
|
@ -106,7 +119,7 @@ class TaskmanArtefact
|
|||
|
||||
$all_src_specs = $this->getSourcesSpec();
|
||||
//let's process a convenience special case
|
||||
if(count($all_src_specs) > 0 && !is_array($all_src_specs[0]))
|
||||
if(count($all_src_specs) > 0 && !is_array($all_src_specs[0]) && !is_int($all_src_specs[0]))
|
||||
$all_src_specs = [$all_src_specs];
|
||||
|
||||
foreach($all_src_specs as $src_idx => $src_spec)
|
||||
|
@ -146,6 +159,18 @@ class TaskmanArtefact
|
|||
);
|
||||
}
|
||||
}
|
||||
//references another artefact by its index
|
||||
else if(is_int($src_spec))
|
||||
{
|
||||
$src_artefact = $this->task->getArtefact($src_spec);
|
||||
|
||||
foreach($src_artefact->getSourcesSpec() as $src_idx => $_)
|
||||
{
|
||||
$this->setSourcesFn($src_idx, fn() => $src_artefact->getSources($src_idx));
|
||||
if($file_changes != null)
|
||||
$this->setSourcesChangedFn($src_idx, fn() => $src_artefact->getChangedSources($src_idx));
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new Exception("Unknown artefact '{$this->getPath()}' source type" . gettype($src_spec));
|
||||
}
|
||||
|
@ -153,17 +178,13 @@ class TaskmanArtefact
|
|||
|
||||
function checkAffectedSources() : bool
|
||||
{
|
||||
$file_changes = $this->task->getFileChanges();
|
||||
|
||||
//let's check if any source is affected
|
||||
foreach($this->getSourcesSpec() as $src_idx => $src_spec)
|
||||
{
|
||||
$sources = $file_changes != null ? $this->getChangedSources($src_idx) : $this->getSources($src_idx);
|
||||
if(is_stale($this->getPath(), $sources))
|
||||
{
|
||||
$this->sources_affected[$src_idx] = true;
|
||||
if($this->isSourcesAffected($src_idx))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,10 +168,19 @@ class TaskmanTask
|
|||
|
||||
try
|
||||
{
|
||||
if($this->getArtefacts() && !$this->_checkIfArtefactsStale())
|
||||
$level = count($TASKMAN_STACK);
|
||||
|
||||
if($this->getArtefacts())
|
||||
{
|
||||
$this->has_run[$args_str] = true;
|
||||
return;
|
||||
$bench = microtime(true);
|
||||
$stale_found = $this->_checkIfArtefactsStale();
|
||||
log(0, "***** ".str_repeat('-', $level)."task '" . $this->getName() . "' artefacts check done(" .
|
||||
round(microtime(true)-$bench,2) . '/' .round(microtime(true)-$TASKMAN_START_TIME,2) . " sec.) *****\n");
|
||||
if(!$stale_found)
|
||||
{
|
||||
$this->has_run[$args_str] = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->is_running = true;
|
||||
|
@ -179,8 +188,6 @@ class TaskmanTask
|
|||
|
||||
$TASKMAN_STACK[] = $this;
|
||||
|
||||
$level = count($TASKMAN_STACK)-1;
|
||||
|
||||
log(0, "***** ".str_repeat('-', $level)."task '" . $this->getName() . "' start *****\n");
|
||||
|
||||
if(!$TASKMAN_NO_DEPS)
|
||||
|
|
Loading…
Reference in New Issue