-
Notifications
You must be signed in to change notification settings - Fork 68
ENG-387 Wait after ingest if needed #3944
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
Conversation
Ref eng-387 Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
Ref eng-387 Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
WalkthroughThe changes introduce a 1-second delay after ingestion in the Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant ingestIfNeeded
participant ingestConsolidatedIntoSearchEngine
participant sleep
Caller->>ingestIfNeeded: invoke()
ingestIfNeeded->>ingestConsolidatedIntoSearchEngine: ingest()
ingestConsolidatedIntoSearchEngine-->>ingestIfNeeded: return
ingestIfNeeded->>sleep: wait(1000ms)
sleep-->>ingestIfNeeded: return
ingestIfNeeded-->>Caller: return
sequenceDiagram
participant ingestPatientConsolidated
participant processErrors
ingestPatientConsolidated->>processErrors: process errors (errors, cxId, patientId, log)
processErrors->>processErrors: Check if errors exist
alt errors exist
processErrors->>console: log error details
processErrors-->>ingestPatientConsolidated: throw MetriportError
else no errors
processErrors-->>ingestPatientConsolidated: return
end
Possibly related PRs
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
npm error code ERR_SSL_WRONG_VERSION_NUMBER ✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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/core/src/command/consolidated/search/fhir-resource/ingest-if-needed.ts (1)
41-41
: Consider making the delay duration configurable.The 1-second delay addresses the PR requirement and likely handles eventual consistency with OpenSearch. However, consider making this configurable to accommodate different environments or ingestion sizes.
-const WAIT_AFTER_INGESTION_IN_MILLIS = 1_000; +const WAIT_AFTER_INGESTION_IN_MILLIS = Config.getWaitAfterIngestionMillis() ?? 1_000;This would allow environment-specific tuning while maintaining the current default behavior.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/core/src/command/consolidated/search/fhir-resource/ingest-if-needed.ts
(2 hunks)packages/core/src/command/consolidated/search/fhir-resource/ingest-lexical.ts
(3 hunks)packages/core/src/external/opensearch/fhir-ingestor.ts
(2 hunks)
🧰 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, 8000 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
, preferisDisabled
- For numeric values, if the type doesn’t convey the unit, add the unit to the name
- Typescript
- Use types
- Prefer
const
instead oflet
- Avoid
any
and casting fromany
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 toundefined
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 (seeprocessAsyncError
andemptyFunction
depending on the case)- Date and Time
- Always use
buildDayjs()
to createdayjs
instances- Prefer
dayjs.duration(...)
to create duration consts and keep them asduration
- 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)
notif ('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
andconsole.error
in packages other than utils, infra and shared,
and try to useout().log
instead- Avoid multi-line logs
- don't send objects as a second parameter to
console.log()
orout().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/core/src/command/consolidated/search/fhir-resource/ingest-if-needed.ts
packages/core/src/command/consolidated/search/fhir-resource/ingest-lexical.ts
packages/core/src/external/opensearch/fhir-ingestor.ts
🧠 Learnings (2)
packages/core/src/command/consolidated/search/fhir-resource/ingest-lexical.ts (1)
Learnt from: leite08
PR: metriport/metriport#3857
File: packages/core/src/command/consolidated/search/fhir-resource/search-lexical.ts:67-82
Timestamp: 2025-05-28T02:51:35.779Z
Learning: In the search-lexical.ts file, the user prefers to bubble up JSON parsing errors rather than catching and logging them. When processing FHIR resources from OpenSearch results, errors should be thrown and allowed to propagate up the call stack instead of being caught and silently ignored.
packages/core/src/external/opensearch/fhir-ingestor.ts (1)
Learnt from: leite08
PR: metriport/metriport#3857
File: packages/core/src/external/opensearch/fhir-ingestor.ts:188-191
Timestamp: 2025-05-28T01:13:24.057Z
Learning: In packages/core/src/external/opensearch/fhir-ingestor.ts, creating new OpenSearch Client instances per operation is acceptable because the client is lightweight and typically only one delete operation is executed per HTTP request.
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: check-pr / lint-build-test
- GitHub Check: Analyze (javascript)
🔇 Additional comments (7)
packages/core/src/external/opensearch/fhir-ingestor.ts (2)
187-187
: LGTM: Logging simplification is appropriate.Removing the debug logging extraction simplifies the logging output while maintaining essential operational logs.
196-196
: LGTM: Debug response logging removal reduces verbosity.Removing the debug log of the response body is appropriate as it reduces log verbosity without losing critical operational information.
packages/core/src/command/consolidated/search/fhir-resource/ingest-if-needed.ts (2)
2-2
: LGTM: Appropriate import for sleep functionality.The import of the sleep utility aligns with the PR objective of adding a wait after ingestion.
9-9
: LGTM: Well-named constant with appropriate unit suffix.The constant follows naming conventions and includes the unit in the name as recommended by the coding guidelines.
packages/core/src/command/consolidated/search/fhir-resource/ingest-lexical.ts (3)
8-8
: LGTM: Import change aligns with updated functionality.The import change from
capture
toout
utility is appropriate for the updated error handling approach.
58-61
: LGTM: Function documentation updated appropriately.The comment accurately reflects the new throwing behavior instead of the previous capturing/logging behavior.
74-80
: Excellent error handling improvement.This change significantly improves error handling by:
- Following coding guidelines: Uses
MetriportError
with structured metadata- Aligning with best practices: Throws errors instead of silently logging them (consistent with retrieved learnings)
- Providing rich context: Includes
cxId
,patientId
, and detailed error counts- Maintaining observability: Still logs before throwing for immediate debugging
The error structure follows the recommended pattern with static message and dynamic data in
extra
.
Dependencies
none
Description
Wait after ingest if needed - see this.
Throw on ingestion error - see ticket.
Testing
Release Plan
Summary by CodeRabbit
Bug Fixes
Chores