Skip to content

Commit

Permalink
fix: Do not send a notification if we have no success or if we alread…
Browse files Browse the repository at this point in the history
…y notified
  • Loading branch information
ptbrowne committed Oct 21, 2020
1 parent 8318ee4 commit 46b7d26
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions src/targets/services/konnectorAlerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,6 @@ const shouldNotify = async (client, trigger, previousStatesByTriggerId) => {
return { ok: false, reason: 'no-previous-state' }
}

// When the previous error is actionable, it's important to check if there
// was a succesful execution since the last failure, otherwise we must not
// send a notification.
if (
isErrorActionable(previousState.last_error) &&
trigger.current_state.last_failure > trigger.current_state.last_execution &&
!flag('banks.konnector-alerts.ignore-previous-status')
) {
return { ok: false, reason: 'previous-error-is-actionable' }
}

if (trigger.current_state.status !== 'errored') {
return { ok: false, reason: 'current-state-is-not-errored' }
}
Expand All @@ -102,6 +91,17 @@ const shouldNotify = async (client, trigger, previousStatesByTriggerId) => {
return { ok: false, reason: 'error-not-actionable' }
}

if (!trigger.current_state.last_success) {
return { ok: false, reason: 'never-been-in-success' }
}

if (
previousState.status === 'errored' &&
isErrorActionable(previousState.last_error)
) {
return { ok: false, reason: 'last-failure-already-notified' }
}

// We do not want to send notifications for jobs that were launched manually
const jobId = trigger.current_state.last_executed_job_id
const { data: job } = await client.query(Q('io.cozy.jobs').getById(jobId))
Expand Down
4 changes: 2 additions & 2 deletions src/targets/services/konnectorAlerts.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ const expectedResults = [
'konnector-2 sent',
'konnector-3 current-state-is-not-errored',
'konnector-4 manual-job',
'konnector-5 sent',
'konnector-5 never-been-in-success',
'konnector-6 sent',
'konnector-7 sent',
'konnector-8 sent'
'konnector-8 last-failure-already-notified'
]

/**
Expand Down

0 comments on commit 46b7d26

Please sign in to comment.