Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: email sending on first execution if error #594

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading