Skip to content

Commit

Permalink
Workflow polling should be 5s default.
Browse files Browse the repository at this point in the history
  • Loading branch information
kporras07 committed Jan 10, 2024
1 parent a754667 commit ab943d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/Commands/WorkflowProcessingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ public function processWorkflow(Workflow $workflow): ?Workflow
$progressBar = $this->getContainer()->get($nickname);
return $progressBar->cycle();
}
$retry_interval = $this->getConfig()->get('http_retry_delay_ms', 100);
$retry_count = 1;
$retry_interval = $this->getConfig()->get('workflow_polling_delay_ms', 5000);
if ($retry_interval < 1000) {
// The API will not allow polling faster than once per second.
$retry_interval = 1000;
}
do {
$workflow->fetch();
$sleep = $retry_interval * $retry_count * 1000;
usleep($sleep);
$retry_count++;
usleep($retry_interval * 1000);
} while (!$workflow->isFinished());
return $workflow;
}
Expand Down
3 changes: 1 addition & 2 deletions src/ProgressBars/TerminusProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ protected function end()
/**
* Sleeps to prevent spamming the API.
*/
protected function sleep($invocation_count = 1)
protected function sleep()
{
$retry_interval = $this->getConfig()->get('http_retry_delay_ms', 100);
$retry_interval = $retry_interval * $invocation_count;
usleep($retry_interval * 1000);
}

Expand Down
13 changes: 13 additions & 0 deletions src/ProgressBars/WorkflowProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ public function cycle()
}
}

/**
* Sleeps to prevent spamming the API.
*/
protected function sleep()
{
$retry_interval = $this->getConfig()->get('workflow_polling_delay_ms', 5000);
if ($retry_interval < 1000) {
// The API will not allow polling faster than once per second.
$retry_interval = 1000;
}
usleep($retry_interval * 1000);
}

/**
* Runs a single iteration of the progress bar.
* @return bool
Expand Down

0 comments on commit ab943d4

Please sign in to comment.