-
Notifications
You must be signed in to change notification settings - Fork 728
feat: move to continue as new pattern (CM-1277) #4262
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7d1409e
feat: move to continue as new pattern
ulemons cc19947
fix: simplify schedule
ulemons 46bea6c
fix: ignoring the error in continue as new logic
ulemons b6c85c9
fix: adding logs
ulemons 62fc6f9
fix: adding logs
ulemons a958108
fix: update schedule
ulemons 837668d
fix: update workflow id
ulemons File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| import { scheduleMavenCritical } from '../maven/schedule' | ||
| import { scheduleMavenIngestion } from '../maven/schedule' | ||
| import { svc } from '../service' | ||
|
|
||
| setImmediate(async () => { | ||
| await svc.init() | ||
| await scheduleMavenCritical() | ||
| await scheduleMavenIngestion() | ||
| await svc.start() | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,78 +1,53 @@ | ||
| import { ScheduleAlreadyRunning, ScheduleOverlapPolicy } from '@temporalio/client' | ||
|
|
||
| import { svc } from '../service' | ||
| import { mavenCriticalWorkflow } from '../workflows' | ||
| import { ingestMavenPackages } from '../workflows' | ||
|
|
||
| export async function scheduleMavenCritical(): Promise<void> { | ||
| const LEGACY_SCHEDULE_ID = 'maven-critical' | ||
|
|
||
| export async function scheduleMavenIngestion(): Promise<void> { | ||
| const { temporal } = svc | ||
| if (!temporal) throw new Error('Temporal client not initialized') | ||
|
|
||
| const scheduleOptions: Parameters<typeof temporal.schedule.create>[0] = { | ||
| scheduleId: 'maven-critical', | ||
| spec: { | ||
| cronExpressions: ['*/1 * * * *'], | ||
| }, | ||
| policies: { | ||
| overlap: ScheduleOverlapPolicy.SKIP, | ||
| catchupWindow: '1 hour', | ||
| }, | ||
| action: { | ||
| type: 'startWorkflow', | ||
| workflowType: mavenCriticalWorkflow, | ||
| taskQueue: 'packages-worker', | ||
| workflowExecutionTimeout: '15 minutes', | ||
| retry: { | ||
| initialInterval: '30 seconds', | ||
| backoffCoefficient: 2, | ||
| maximumAttempts: 3, | ||
| }, | ||
| args: [], | ||
| }, | ||
| try { | ||
| await temporal.schedule.getHandle(LEGACY_SCHEDULE_ID).delete() | ||
| svc.log.info({ scheduleId: LEGACY_SCHEDULE_ID }, 'Deleted legacy schedule.') | ||
| } catch (err) { | ||
| svc.log.warn( | ||
| { err, scheduleId: LEGACY_SCHEDULE_ID }, | ||
| 'Failed to delete legacy schedule (may not exist).', | ||
| ) | ||
| } | ||
|
ulemons marked this conversation as resolved.
|
||
|
|
||
| try { | ||
| await temporal.schedule.create(scheduleOptions) | ||
| await temporal.schedule.create({ | ||
| scheduleId: 'maven-ingestion', | ||
| spec: { | ||
| cronExpressions: ['0 9 * * *'], | ||
| }, | ||
|
ulemons marked this conversation as resolved.
|
||
| policies: { | ||
| overlap: ScheduleOverlapPolicy.SKIP, | ||
| catchupWindow: '1 hour', | ||
| }, | ||
| action: { | ||
| type: 'startWorkflow', | ||
| workflowType: ingestMavenPackages, | ||
| workflowId: 'maven-daily-enrichment', | ||
| taskQueue: 'packages-worker', | ||
| workflowRunTimeout: '24 hours', | ||
| retry: { | ||
| initialInterval: '30 seconds', | ||
| backoffCoefficient: 2, | ||
| maximumAttempts: 3, | ||
| }, | ||
| args: [], | ||
| }, | ||
| }) | ||
| } catch (err) { | ||
| if (err instanceof ScheduleAlreadyRunning) { | ||
| svc.log.info('Schedule maven-critical already exists, skipping creation.') | ||
| svc.log.info('Schedule maven-ingestion already exists, skipping creation.') | ||
| } else { | ||
| throw err | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // export async function scheduleMavenNonCritical(): Promise<void> { | ||
| // const { temporal } = svc | ||
| // if (!temporal) throw new Error('Temporal client not initialized') | ||
|
|
||
| // try { | ||
| // await temporal.schedule.create({ | ||
| // scheduleId: 'maven-non-critical', | ||
| // spec: { | ||
| // cronExpressions: ['*/10 * * * *'], | ||
| // }, | ||
| // policies: { | ||
| // overlap: ScheduleOverlapPolicy.SKIP, | ||
| // catchupWindow: '1 hour', | ||
| // }, | ||
| // action: { | ||
| // type: 'startWorkflow', | ||
| // workflowType: mavenNonCriticalWorkflow, | ||
| // taskQueue: 'packages-worker', | ||
| // workflowExecutionTimeout: '5 minutes', | ||
| // retry: { | ||
| // initialInterval: '30 seconds', | ||
| // backoffCoefficient: 2, | ||
| // maximumAttempts: 3, | ||
| // }, | ||
| // args: [], | ||
| // }, | ||
| // }) | ||
| // } catch (err) { | ||
| // if (err instanceof ScheduleAlreadyRunning) { | ||
| // svc.log.info('Schedule maven-non-critical already registered.') | ||
| // } else { | ||
| // throw err | ||
| // } | ||
| // } | ||
| // } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,21 @@ | ||
| import { proxyActivities } from '@temporalio/workflow' | ||
| import { continueAsNew, log, proxyActivities } from '@temporalio/workflow' | ||
|
|
||
| import type * as activities from './activities' | ||
|
|
||
| const { processMavenCriticalBatch } = proxyActivities<typeof activities>({ | ||
| const acts = proxyActivities<typeof activities>({ | ||
| startToCloseTimeout: '15 minutes', | ||
| retry: { | ||
| initialInterval: '30 seconds', | ||
| backoffCoefficient: 2, | ||
| maximumAttempts: 5, | ||
| }, | ||
| }) | ||
|
|
||
| const { processMavenNonCriticalBatch } = proxyActivities<typeof activities>({ | ||
| startToCloseTimeout: '5 minutes', | ||
| }) | ||
|
|
||
| export async function mavenCriticalWorkflow(): Promise<void> { | ||
| await processMavenCriticalBatch() | ||
| } | ||
|
|
||
| export async function mavenNonCriticalWorkflow(): Promise<void> { | ||
| await processMavenNonCriticalBatch() | ||
| export async function ingestMavenPackages(): Promise<void> { | ||
| const result = await acts.processMavenCriticalBatch() | ||
| if (result.processed + result.skipped + result.unchanged === 0) { | ||
| log.info('Maven ingestion complete — no more work, exiting.', { ...result }) | ||
| return | ||
|
ulemons marked this conversation as resolved.
|
||
| } | ||
|
ulemons marked this conversation as resolved.
|
||
| await continueAsNew<typeof ingestMavenPackages>() | ||
|
ulemons marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.