Skip to content

Commit

Permalink
fix: email sending on first execution if error
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren committed Nov 30, 2023
1 parent 74cec11 commit e793cb9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions examples/workflows/new_github_stars.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Alert when there are new GitHub Stars utilizing keepstate
workflow:
id: new-github-stars
description: Get new GitHub Stars
description: Notify Slack about new GitHub star for keephq/keep
triggers:
- type: interval
value: 300
Expand All @@ -20,7 +20,7 @@ workflow:
condition:
- name: assert-condition
type: assert
assert: "{{ steps.get-github-stars.results.new_stargazers_count }} == 0" # if there are more than 0 new stargazers, trigger the action
assert: "{{ steps.get-github-stars.results.new_stargazers_count }} > 0" # if there are more than 0 new stargazers, trigger the action
provider:
type: slack
config: " {{ providers.slack-demo }} "
Expand Down
15 changes: 8 additions & 7 deletions keep/workflowmanager/workflowscheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,6 @@ def _finish_workflow_execution(
status: WorkflowStatus,
error=None,
):
# get the previous workflow execution id
previous_execution = get_previous_execution_id(
tenant_id, workflow_id, workflow_execution_id
)
# mark the workflow execution as finished in the db
finish_workflow_execution_db(
tenant_id=tenant_id,
Expand All @@ -355,10 +351,15 @@ def _finish_workflow_execution(
status=status.value,
error=error,
)
# get the previous workflow execution id
previous_execution = get_previous_execution_id(
tenant_id, workflow_id, workflow_execution_id
)
# if error, send an email
if (
status == WorkflowStatus.ERROR
and previous_execution.status != WorkflowStatus.ERROR.value
if status == WorkflowStatus.ERROR and (
previous_execution
is None # this means this is the first execution, for example
or previous_execution.status != WorkflowStatus.ERROR.value
):
workflow = get_workflow_db(tenant_id=tenant_id, workflow_id=workflow_id)
self.logger.info(
Expand Down

0 comments on commit e793cb9

Please sign in to comment.