Skip to content

Commit 07ca8cd

Browse files
authored
fix: email sending on first execution if error (#594)
1 parent 74cec11 commit 07ca8cd

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

examples/workflows/new_github_stars.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Alert when there are new GitHub Stars utilizing keepstate
22
workflow:
33
id: new-github-stars
4-
description: Get new GitHub Stars
4+
description: Notify Slack about new GitHub star for keephq/keep
55
triggers:
66
- type: interval
77
value: 300
@@ -20,7 +20,7 @@ workflow:
2020
condition:
2121
- name: assert-condition
2222
type: assert
23-
assert: "{{ steps.get-github-stars.results.new_stargazers_count }} == 0" # if there are more than 0 new stargazers, trigger the action
23+
assert: "{{ steps.get-github-stars.results.new_stargazers_count }} > 0" # if there are more than 0 new stargazers, trigger the action
2424
provider:
2525
type: slack
2626
config: " {{ providers.slack-demo }} "

keep/workflowmanager/workflowscheduler.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,6 @@ def _finish_workflow_execution(
343343
status: WorkflowStatus,
344344
error=None,
345345
):
346-
# get the previous workflow execution id
347-
previous_execution = get_previous_execution_id(
348-
tenant_id, workflow_id, workflow_execution_id
349-
)
350346
# mark the workflow execution as finished in the db
351347
finish_workflow_execution_db(
352348
tenant_id=tenant_id,
@@ -355,10 +351,15 @@ def _finish_workflow_execution(
355351
status=status.value,
356352
error=error,
357353
)
354+
# get the previous workflow execution id
355+
previous_execution = get_previous_execution_id(
356+
tenant_id, workflow_id, workflow_execution_id
357+
)
358358
# if error, send an email
359-
if (
360-
status == WorkflowStatus.ERROR
361-
and previous_execution.status != WorkflowStatus.ERROR.value
359+
if status == WorkflowStatus.ERROR and (
360+
previous_execution
361+
is None # this means this is the first execution, for example
362+
or previous_execution.status != WorkflowStatus.ERROR.value
362363
):
363364
workflow = get_workflow_db(tenant_id=tenant_id, workflow_id=workflow_id)
364365
self.logger.info(

0 commit comments

Comments
 (0)