Skip to content

Commit 16bd746

Browse files
committed
[Node] update update wf retry details
1 parent e8b34de commit 16bd746

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

packages/node/octobot_node/constants.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#
1414
# You should have received a copy of the GNU General Public
1515
# License along with OctoBot. If not, see <https://www.gnu.org/licenses/>.
16+
import os
17+
1618
try:
1719
import octobot.constants as octobot_constants
1820
BASE_LOGS_FOLDER = octobot_constants.LOGS_FOLDER
@@ -22,6 +24,11 @@
2224
AUTOMATION_LOGS_FOLDER = f"{BASE_LOGS_FOLDER}/automations"
2325
PARENT_WORKFLOW_ID_LENGTH = 36 # length of a UUID4
2426

27+
# default to 10 retry after 1, 2, 4, 8, 16, ... 1024 seconds (total of 2047 seconds)
28+
AUTOMATION_WORKFLOW_RETRY_INTERVAL_SECONDS = float(os.getenv("AUTOMATION_WORKFLOW_RETRY_INTERVAL_SECONDS", 1.0))
29+
AUTOMATION_WORKFLOW_MAX_ITERATION_RETRIES = int(os.getenv("AUTOMATION_WORKFLOW_MAX_ITERATION_RETRIES", 10))
30+
AUTOMATION_WORKFLOW_BACKOFF_RATE = float(os.getenv("AUTOMATION_WORKFLOW_BACKOFF_RATE", 2))
31+
2532
TASKS_ENCRYPTION_ENV_VARS = [
2633
"TASKS_SERVER_RSA_PRIVATE_KEY",
2734
"TASKS_SERVER_ECDSA_PRIVATE_KEY",

packages/node/octobot_node/scheduler/workflows/automation_workflow.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import time
1818
import typing
1919
import dbos
20+
import os
2021

2122
import octobot_commons.logging
2223

@@ -27,6 +28,7 @@
2728
import octobot_node.models
2829
import octobot_node.scheduler.octobot_flow_client as octobot_flow_client
2930
import octobot_node.scheduler.task_context
31+
import octobot_node.constants as constants
3032
import octobot_node.scheduler.workflows.params as params
3133
import octobot_node.errors as errors
3234

@@ -36,11 +38,6 @@
3638
from octobot_node.scheduler import SCHEDULER # avoid circular import
3739

3840

39-
INTERVAL_SECONDS = 1.0
40-
MAX_ITERATION_RETRIES = 3
41-
BACKOFF_RATE = 2.0
42-
43-
4441
@SCHEDULER.INSTANCE.dbos_class()
4542
class AutomationWorkflow:
4643
# Always use dict as input to parse minimizable dataclasses and facilitate data format updates
@@ -108,9 +105,9 @@ async def execute_automation(inputs: dict) -> typing.Optional[str]:
108105
@SCHEDULER.INSTANCE.step(
109106
name="execute_iteration",
110107
retries_allowed=True,
111-
interval_seconds = INTERVAL_SECONDS,
112-
max_attempts=MAX_ITERATION_RETRIES,
113-
backoff_rate=BACKOFF_RATE,
108+
interval_seconds = constants.AUTOMATION_WORKFLOW_RETRY_INTERVAL_SECONDS,
109+
max_attempts=constants.AUTOMATION_WORKFLOW_MAX_ITERATION_RETRIES,
110+
backoff_rate=constants.AUTOMATION_WORKFLOW_BACKOFF_RATE,
114111
)
115112
async def execute_iteration(inputs: dict, actions_update: typing.Optional[dict]) -> dict:
116113
"""

packages/node/tests/scheduler/workflows/test_automation_workflow.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import octobot_copy.entities
3131
import octobot_node.config
32+
import octobot_node.constants
3233
import octobot_node.enums
3334
import octobot_node.scheduler
3435
import octobot_node.scheduler.workflows
@@ -410,7 +411,7 @@ async def test_execute_automation(
410411
assert parsed_output.error == expected_error_status
411412
assert (
412413
run_mock.await_count
413-
== octobot_node.scheduler.workflows.automation_workflow.MAX_ITERATION_RETRIES
414+
== octobot_node.constants.AUTOMATION_WORKFLOW_MAX_ITERATION_RETRIES
414415
)
415416
mock_logger.exception.assert_called_once()
416417
mock_process.assert_not_called()
@@ -1033,12 +1034,12 @@ async def test_execute_automation_execute_iteration_retries_octobot_actions_job_
10331034
temp_dbos_scheduler,
10341035
):
10351036
"""
1036-
DBOS execute_iteration is configured with max_attempts=MAX_ITERATION_RETRIES.
1037+
DBOS execute_iteration is configured with max_attempts=AUTOMATION_WORKFLOW_MAX_ITERATION_RETRIES.
10371038
When OctoBotActionsJob.run() fails on early attempts then succeeds, the step should
10381039
retry and eventually complete without failing the workflow. A processed action may still
10391040
report an error_status; that value is copied to AutomationWorkflowOutput.error on completion.
10401041
"""
1041-
max_attempts = octobot_node.scheduler.workflows.automation_workflow.MAX_ITERATION_RETRIES
1042+
max_attempts = octobot_node.constants.AUTOMATION_WORKFLOW_MAX_ITERATION_RETRIES
10421043
task = octobot_node.models.Task(
10431044
name="retry_policy_test",
10441045
content="{}",
@@ -1120,8 +1121,8 @@ async def test_execute_automation_execute_iteration_exhausts_retries_when_octobo
11201121
import_automation_workflow,
11211122
temp_dbos_scheduler,
11221123
):
1123-
"""After MAX_ITERATION_RETRIES failed OctoBotActionsJob.run() calls, the step must stop retrying."""
1124-
max_attempts = octobot_node.scheduler.workflows.automation_workflow.MAX_ITERATION_RETRIES
1124+
"""After AUTOMATION_WORKFLOW_MAX_ITERATION_RETRIES failed OctoBotActionsJob.run() calls, the step must stop retrying."""
1125+
max_attempts = octobot_node.constants.AUTOMATION_WORKFLOW_MAX_ITERATION_RETRIES
11251126
task = octobot_node.models.Task(
11261127
name="retry_exhausted_test",
11271128
content="{}",

0 commit comments

Comments
 (0)