Skip to content

Commit

Permalink
chore: remove limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ogp-weeloong committed May 2, 2024
1 parent 6aa64af commit 905a06e
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/backend/src/graphql/mutations/bulk-retry-executions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import actionQueue from '@/queues/action'

import type { MutationResolvers } from '../__generated__/types.generated'

const SEVEN_DAYS_IN_MS = 7 * 24 * 60 * 60 * 1000

const bulkRetryExecutions: MutationResolvers['bulkRetryExecutions'] = async (
_parent,
params,
Expand All @@ -18,8 +20,12 @@ const bulkRetryExecutions: MutationResolvers['bulkRetryExecutions'] = async (
.where('executions.flow_id', params.input.flowId)
.where('executions.test_run', false)
.where('executions.status', 'failure')
.where(
'executions.created_at',
'>=',
new Date(Date.now() - SEVEN_DAYS_IN_MS).toISOString(),
)
.select('executions.id')
.limit(500)
let latestFailedExecutionSteps = await ExecutionStep.query()
.whereIn(
'execution_id',
Expand All @@ -32,10 +38,11 @@ const bulkRetryExecutions: MutationResolvers['bulkRetryExecutions'] = async (
.distinctOn('execution_id')
.select('execution_id', 'status', 'job_id')

// Double check that latest steps for each failed execution is a failure.
// Double check that latest steps for each failed execution is a failure and
// has a valid job ID.
latestFailedExecutionSteps = latestFailedExecutionSteps.filter(
(executionStep) => {
const { id: executionStepId, executionId, status } = executionStep
const { id: executionStepId, executionId, status, jobId } = executionStep
if (status !== 'failure') {
logger.error(
'Latest execution step is not failed for a failed execution',
Expand All @@ -47,6 +54,15 @@ const bulkRetryExecutions: MutationResolvers['bulkRetryExecutions'] = async (
)
return false
}
if (jobId === null || jobId === undefined) {
// For fresh per-app queues, job ID can be 0.
logger.error('Latest execution step does not have a job ID', {
event: 'bulk-retry-step-no-job-id',
executionId: executionId,
executionStepId: executionStepId,
})
return false
}
return true
},
)
Expand Down Expand Up @@ -86,6 +102,7 @@ const bulkRetryExecutions: MutationResolvers['bulkRetryExecutions'] = async (
const allSuccessfullyRetried = !retryAttempts.find(
(attempt) => attempt.status === 'rejected',
)

if (!allSuccessfullyRetried) {
// Actually we can do some more processing to see which IDs failed but nvm.
logger.warn('Some attempts in bulk execution retry failed', {
Expand Down

0 comments on commit 905a06e

Please sign in to comment.