Skip to content

Commit

Permalink
accept array format for exponential backoff (#926)
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid authored Nov 19, 2020
1 parent d08d10e commit cb4e564
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ProvisioningPlan.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ protected function convert($supervisor, $options)
$key = $key === 'tries' ? 'max_tries' : $key;
$key = $key === 'processes' ? 'max_processes' : $key;
$value = $key === 'queue' && is_array($value) ? implode(',', $value) : $value;
$value = $key === 'backoff' && is_array($value) ? implode(',', $value) : $value;

return [Str::camel($key) => $value];
})->all();
Expand Down
2 changes: 1 addition & 1 deletion src/SupervisorOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class SupervisorOptions
/**
* The number of seconds to wait before retrying a job that encountered an uncaught exception.
*
* @var int
* @var string
*/
public $backoff;

Expand Down
17 changes: 17 additions & 0 deletions tests/Feature/ProvisioningPlanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,21 @@ public function test_plan_is_converted_into_array_of_supervisor_options()

$this->assertSame(20, $results['local']['supervisor-2']->maxProcesses);
}

public function test_backoff_is_translated_to_string_form()
{
$plan = [
'local' => [
'supervisor-2' => [
'connection' => 'redis',
'queue' => 'local-supervisor-2-queue',
'backoff' => [30, 60],
],
],
];

$results = (new ProvisioningPlan(MasterSupervisor::name(), $plan))->toSupervisorOptions();

$this->assertSame('30,60', $results['local']['supervisor-2']->backoff);
}
}

0 comments on commit cb4e564

Please sign in to comment.