|
| 1 | +import { ScheduleAlreadyRunning, ScheduleOverlapPolicy } from '@temporalio/client' |
| 2 | + |
| 3 | +import { SlackChannel, SlackPersona, sendSlackNotification } from '@crowd/slack' |
| 4 | + |
| 5 | +import { svc } from '../main' |
| 6 | +import { snowflakeS3ExportScheduler } from '../workflows' |
| 7 | + |
| 8 | +export const scheduleSnowflakeS3Export = async () => { |
| 9 | + try { |
| 10 | + await svc.temporal.schedule.create({ |
| 11 | + scheduleId: 'snowflake-s3-export', |
| 12 | + spec: { |
| 13 | + cronExpressions: ['0 0 * * *'], |
| 14 | + }, |
| 15 | + policies: { |
| 16 | + overlap: ScheduleOverlapPolicy.SKIP, |
| 17 | + catchupWindow: '1 minute', |
| 18 | + }, |
| 19 | + action: { |
| 20 | + type: 'startWorkflow', |
| 21 | + workflowType: snowflakeS3ExportScheduler, |
| 22 | + taskQueue: 'snowflakeConnectors', |
| 23 | + retry: { |
| 24 | + initialInterval: '15 seconds', |
| 25 | + backoffCoefficient: 2, |
| 26 | + maximumAttempts: 3, |
| 27 | + }, |
| 28 | + args: [], |
| 29 | + }, |
| 30 | + }) |
| 31 | + } catch (err) { |
| 32 | + if (err instanceof ScheduleAlreadyRunning) { |
| 33 | + svc.log.info('Schedule already registered in Temporal.') |
| 34 | + svc.log.info('Configuration may have changed since. Please make sure they are in sync.') |
| 35 | + } else { |
| 36 | + svc.log.error({ err }, 'Failed to create snowflake-s3-export schedule') |
| 37 | + sendSlackNotification( |
| 38 | + SlackChannel.INTEGRATION_NOTIFICATIONS, |
| 39 | + SlackPersona.ERROR_REPORTER, |
| 40 | + 'Snowflake S3 Export Schedule Failed', |
| 41 | + `Failed to create the \`snowflake-s3-export\` Temporal schedule.\n\n*Error:* ${err.message || err}`, |
| 42 | + ) |
| 43 | + } |
| 44 | + } |
| 45 | +} |
0 commit comments