-
Notifications
You must be signed in to change notification settings - Fork 1
Implement weekly financial report schedule #115
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4e7e2a3
Implement weekly financial report schedule setup in worker initializa…
anatolyshipitz 9eb335d
Enhance error logging during weekly report schedule creation
anatolyshipitz 95a45d0
Update temporal configuration documentation for clarity
anatolyshipitz 63945a5
Refine logging and documentation for schedule setup
anatolyshipitz 4a8ecda
Refactor logging implementation and update imports
anatolyshipitz 3eb305d
Update workflow type in weekly report schedule configuration
anatolyshipitz 13ff085
Update logger level and enhance schedule validation logic
anatolyshipitz 7b07b52
Remove export of logger from index.ts to streamline module exports
anatolyshipitz 6594469
Refactor schedule creation to include race condition protection
anatolyshipitz 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { Client } from '@temporalio/client'; | ||
|
|
||
| import { logger } from '../index'; | ||
| import { weeklyFinancialReportsWorkflow } from '../workflows'; | ||
| import { workerConfig } from './worker'; | ||
|
|
||
| const SCHEDULE_ID = 'weekly-financial-report-schedule'; | ||
|
|
||
| /** | ||
| * Sets up the weekly financial report schedule | ||
| * Schedule runs every Tuesday at 1 PM America/New_York time (EST/EDT) | ||
| * @param client - Temporal client instance | ||
| */ | ||
| export async function setupWeeklyReportSchedule(client: Client): Promise<void> { | ||
| try { | ||
| const scheduleHandle = client.schedule.getHandle(SCHEDULE_ID); | ||
|
|
||
| // Check if schedule already exists | ||
| try { | ||
| await scheduleHandle.describe(); | ||
| logger.info(`Schedule ${SCHEDULE_ID} already exists, skipping creation`); | ||
|
|
||
| return; | ||
| } catch (error) { | ||
| const errorMessage = | ||
| error instanceof Error ? error.message : String(error); | ||
|
|
||
| // Schedule doesn't exist, create it | ||
| logger.info( | ||
| `Creating schedule ${SCHEDULE_ID} with error: ${errorMessage}`, | ||
| ); | ||
| } | ||
|
|
||
| await client.schedule.create({ | ||
| scheduleId: SCHEDULE_ID, | ||
| spec: { | ||
| cronExpressions: ['0 13 * * 2'], // Every Tuesday at 1 PM | ||
| timezone: 'America/New_York', // Automatically handles EST/EDT transitions | ||
| }, | ||
| action: { | ||
| type: 'startWorkflow', | ||
| workflowType: weeklyFinancialReportsWorkflow, | ||
| taskQueue: workerConfig.taskQueue, | ||
| workflowId: `weekly-financial-report-scheduled`, | ||
| }, | ||
| policies: { | ||
| overlap: 'SKIP', // Skip if previous run is still in progress | ||
| catchupWindow: '1 day', // Catch up missed runs within 1 day | ||
| }, | ||
| }); | ||
|
|
||
| logger.info( | ||
| `Successfully created schedule ${SCHEDULE_ID} for weekly financial reports`, | ||
| ); | ||
| } catch (error) { | ||
| logger.error( | ||
| `Failed to setup schedule ${SCHEDULE_ID}: ${error instanceof Error ? error.message : String(error)}`, | ||
| ); | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Schedule configuration exported for documentation and testing | ||
| */ | ||
| export const scheduleConfig = { | ||
| scheduleId: SCHEDULE_ID, | ||
| cronExpression: '0 13 * * 2', | ||
| timezone: 'America/New_York', | ||
| description: 'Runs every Tuesday at 1 PM EST/EDT', | ||
| } as const; | ||
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
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.