Skip to content

Conversation

thomasyopes
Copy link
Contributor

@thomasyopes thomasyopes commented Jun 20, 2025

Ref: ENG-433

Issues:

Description

  • moving scheduler starter to after api

Testing

  • Local
    • cdk diff
  • Staging
    • lambda has full URL
  • Sandbox
    • lambda has full URL
  • Production
    • lambda has full URL

Release Plan

  • Merge this

Summary by CodeRabbit

  • New Features

    • Introduced a scheduled job system that automatically triggers tasks at defined intervals.
  • Chores

    • Integrated the job scheduler setup into the main API stack for improved infrastructure management.
    • Streamlined job scheduling configuration by consolidating related logic into a dedicated module.

Ref: ENG-433

Ref: #1040
Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Copy link

linear bot commented Jun 20, 2025

Copy link

coderabbitai bot commented Jun 20, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

A new jobs-scheduler.ts module is introduced to encapsulate the creation of a scheduled Lambda job. The API stack is updated to invoke this new scheduler setup, while the previous direct Lambda creation is removed from the jobs stack. No changes are made to public interfaces or exported entities except for new exports in the scheduler module.

Changes

File(s) Change Summary
packages/infra/lib/jobs/jobs-scheduler.ts Added new module exporting JobsSchedulerProps type and createJobsScheduler function for configuring and deploying a scheduled Lambda job.
packages/infra/lib/api-stack.ts Imported and invoked createJobsScheduler within the APIStack constructor to set up the job scheduler.
packages/infra/lib/jobs/jobs-stack.ts Removed direct import and usage of createScheduledLambda for job scheduling.

Sequence Diagram(s)

sequenceDiagram
    participant APIStack
    participant JobsScheduler
    participant ScheduledLambda

    APIStack->>JobsScheduler: createJobsScheduler(props)
    JobsScheduler->>ScheduledLambda: createScheduledLambda(config)
    ScheduledLambda-->>JobsScheduler: Lambda scheduled
    JobsScheduler-->>APIStack: Scheduler setup complete
Loading

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error code ERR_SSL_WRONG_VERSION_NUMBER
npm error errno ERR_SSL_WRONG_VERSION_NUMBER
npm error request to https://10.0.0.28:4873/punycode/-/punycode-2.3.1.tgz failed, reason: C09C2A42B17F0000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:354:
npm error
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-20T00_31_11_708Z-debug-0.log


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1b595f and 8fcb4a7.

📒 Files selected for processing (1)
  • packages/infra/lib/jobs/jobs-scheduler.ts (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/infra/lib/jobs/jobs-scheduler.ts (1)

17-24: Consider making the function name configurable.

The getSettings function works correctly, but the hardcoded function name "StartPatientJobsScheduler" reduces flexibility. Consider making it configurable through the config or props.

 function getSettings(props: JobsSchedulerProps, config: NonNullable<EnvConfig["jobs"]>) {
   return {
     ...props,
-    name: "StartPatientJobsScheduler",
+    name: config.lambdaName ?? "StartPatientJobsScheduler",
     scheduleExpression: config.startPatientJobsSchedulerScheduleExpression,
     url: `http://${props.apiAddress}${config.startPatientJobsSchedulerUrl}`,
   };
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d156d55 and e1b595f.

📒 Files selected for processing (3)
  • packages/infra/lib/api-stack.ts (2 hunks)
  • packages/infra/lib/jobs/jobs-scheduler.ts (1 hunks)
  • packages/infra/lib/jobs/jobs-stack.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/infra/lib/jobs/jobs-stack.ts
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.ts`: - Use the Onion Pattern to organize a package's code in layers - Try to use immutable code and avoid sharing state across different functions, objects, and systems - Try...

**/*.ts: - Use the Onion Pattern to organize a package's code in layers

  • Try to use immutable code and avoid sharing state across different functions, objects, and systems
  • Try to build code that's idempotent whenever possible
  • Prefer functional programming style functions: small, deterministic, 1 input, 1 output
  • Minimize coupling / dependencies
  • Avoid modifying objects received as parameter
  • Only add comments to code to explain why something was done, not how it works
  • Naming
    • classes, enums: PascalCase
    • constants, variables, functions: camelCase
    • file names: kebab-case
    • table and column names: snake_case
    • Use meaningful names, so whoever is reading the code understands what it means
    • Don’t use negative names, like notEnabled, prefer isDisabled
    • For numeric values, if the type doesn’t convey the unit, add the unit to the name
  • Typescript
    • Use types
    • Prefer const instead of let
    • Avoid any and casting from any to other types
    • Type predicates: only applicable to narrow down the type, not to force a complete type conversion
    • Prefer deconstructing parameters for functions instead of multiple parameters that might be of
      the same type
    • Don’t use null inside the app, only on code interacting with external interfaces/services,
      like DB and HTTP; convert to undefined before sending inwards into the code
    • Use async/await instead of .then()
    • Use the strict equality operator ===, don’t use abstract equality operator ==
    • When calling a Promise-returning function asynchronously (i.e., not awaiting), use .catch() to
      handle errors (see processAsyncError and emptyFunction depending on the case)
    • Date and Time
      • Always use buildDayjs() to create dayjs instances
      • Prefer dayjs.duration(...) to create duration consts and keep them as duration
  • Prefer Nullish Coalesce (??) than the OR operator (||) to provide a default value
  • Avoid creating arrow functions
  • Use truthy syntax instead of in - i.e., if (data.link) not if ('link' in data)
  • Error handling
    • Pass the original error as the new one’s cause so the stack trace is persisted
    • Error messages should have a static message - add dynamic data to MetriportError's additionalInfo prop
    • Avoid sending multiple events to Sentry for a single error
  • Global constants and variables
    • Move literals to constants declared after imports when possible (avoid magic numbers)
    • Avoid shared, global objects
  • Avoid using console.log and console.error in packages other than utils, infra and shared,
    and try to use out().log instead
  • Avoid multi-line logs
    • don't send objects as a second parameter to console.log() or out().log()
    • don't create multi-line strings when using JSON.stringify()
  • Use eslint to enforce code style
  • Use prettier to format code
  • max column length is 100 chars
  • multi-line comments use /** */
  • scripts: top-level comments go after the import
  • packages/infra/lib/api-stack.ts
  • packages/infra/lib/jobs/jobs-scheduler.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: check-branch
  • GitHub Check: check-pr / lint-build-test
🔇 Additional comments (3)
packages/infra/lib/api-stack.ts (2)

49-49: LGTM: Clean import addition.

The import follows the established pattern and correctly imports the new scheduler module.


740-746: LGTM: Proper integration of job scheduler setup.

The call to createJobsScheduler is well-positioned after the API service creation, which aligns with the PR objective of moving the job scheduler starter to after API initialization. The parameters passed are consistent with similar function calls in this file.

packages/infra/lib/jobs/jobs-scheduler.ts (1)

9-15: LGTM: Well-defined interface.

The JobsSchedulerProps type clearly defines the required parameters with appropriate types. The optional alarmSnsAction parameter follows AWS CDK patterns.

};
}

export function createJobsScheduler(props: JobsSchedulerProps) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: return type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


export function createJobsScheduler(props: JobsSchedulerProps) {
const config = getConfig();
if (!config.jobs) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hypernit: explicitly return undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Ref: ENG-433

Ref: #1040
Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
@thomasyopes thomasyopes merged commit 702ad2c into eng-433-moving-files Jun 20, 2025
9 of 10 checks passed
@thomasyopes thomasyopes deleted the eng-433-moving-files-2 branch June 20, 2025 00:30
@RamilGaripov RamilGaripov mentioned this pull request Jun 26, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants