Skip to content
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

feat(fhircast): add heartbeat event #3350

Merged
merged 10 commits into from
Nov 28, 2023
Merged

Conversation

ThatOneBro
Copy link
Member

@ThatOneBro ThatOneBro commented Nov 21, 2023

Closes #3356

Copy link

vercel bot commented Nov 21, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
medplum-app ⬜️ Ignored (Inspect) Visit Preview Nov 28, 2023 10:08pm
medplum-storybook ⬜️ Ignored (Inspect) Visit Preview Nov 28, 2023 10:08pm
medplum-www ⬜️ Ignored (Inspect) Visit Preview Nov 28, 2023 10:08pm

Copy link
Contributor

sweep-ai bot commented Nov 21, 2023

Apply Sweep Rules to your PR?

  • Apply: All new business logic should have corresponding unit tests.
  • Apply: Refactor large functions to be more modular.
  • Apply: Add docstrings to all functions and file headers.

Copy link

github-actions bot commented Nov 21, 2023

Messages
📖 @medplum/core: 142.2 kB
📖 @medplum/react: 183.3 kB

Generated by 🚫 dangerJS against 7854cab

Copy link
Member

@codyebberson codyebberson left a comment

Choose a reason for hiding this comment

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

Let's discuss next week. My assumption was that the client would send the heartbeat, not the server. If we can avoid it, my preference would be to try to avoid timers in server whenever possible. The whole HeartbeatStore class could be avoided if the client manages the timers.

@ThatOneBro
Copy link
Member Author

ThatOneBro commented Nov 24, 2023

Just implementing it per the FHIRcast spec:
https://build.fhir.org/ig/HL7/fhircast-docs/3-2-2-Heartbeat.html#:~:text=The%20Heartbeat.html%20event%20is%20sent%20regularly%20by%20the%20Hub

EDIT: Also I think relying on the client to send the heartbeat wouldn't fix it for the external clients that we don't manage, since they would still have to implement it themselves.

@ThatOneBro
Copy link
Member Author

Potentially we could use one timer and just blast out the heartbeat to all the tracked topics.

@codyebberson
Copy link
Member

Just implementing it per the FHIRcast spec:

Ahh, good find! I stand corrected. Ok, need to noodle on that.

@ThatOneBro
Copy link
Member Author

@codyebberson I refactored this to use only one timer that gets cleaned up if there are no active topics. Does this make more sense maybe?

Copy link
Member

@codyebberson codyebberson left a comment

Choose a reason for hiding this comment

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

Nice, thanks @ThatOneBro

See one comment on cleanupPromises array. We can push that to separate commit if you prefer.

Also, as a thought exercise, do you think this could work with the Medplum Agent websocket connection? It will need a similar heartbeat feature. No need to force it if it's too unnatural, but if it fits, that'd be neat.

const redis = getRedis();
const redisSubscriber = redis.duplicate();
const deferredCleanupPromise = createDeferredPromise();
cleanupPromises.push(deferredCleanupPromise.promise);
Copy link
Member

Choose a reason for hiding this comment

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

It looks like we're only adding to cleanupPromises, and never removing? If lots of frequent connect/disconnects, would this array continue to grow? Probably fine in the short term when not many users, but ideally we'd remove promises from the array on websocket close.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I think in an earlier iteration I couldn't figure out how to safely remove promises reliably, but I guess when they are resolved they can probably just be removed. I'll fix that

@ThatOneBro
Copy link
Member Author

ThatOneBro commented Nov 28, 2023

Also, as a thought exercise, do you think this could work with the Medplum Agent websocket connection? It will need a similar heartbeat feature. No need to force it if it's too unnatural, but if it fits, that'd be neat.

I think that could work. Do you think it would be best just to turn this into a generalized module that gets pulled into both files? Would we want to drive both off of the same timer?

Copy link

sonarcloud bot commented Nov 28, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

82.5% 82.5% Coverage
0.0% 0.0% Duplication

@ThatOneBro ThatOneBro added this pull request to the merge queue Nov 28, 2023
Merged via the queue into main with commit 8c94b8d Nov 28, 2023
15 checks passed
@ThatOneBro ThatOneBro deleted the derrick-add-fhircast-heartbeat branch November 28, 2023 22:58
medplumbot added a commit that referenced this pull request Dec 2, 2023
Fixes #3391 - setup git in preapare-release-yml (#3448)
Create example bots that use a shared code library (#3441)
Fixes #2789 - support 'delete' subscriptions with bots (#3426) (#3445)
Fixes #3391 - github action for prepare-release.sh (#3443)
Revert "Fixes #2789 - support 'delete' subscriptions with bots (#3426)" (#3444)
Update AWS instructions (#3437)
Bump @adobe/css-tools from 4.3.1 to 4.3.2 (#3440)
Fix ValidBot warnings (#3438)
Fixes #3404 - add Referrer-Policy and Permissions-Policy headers (#3436)
Fixes #2789 - support 'delete' subscriptions with bots (#3426)
Agent source cleanup (#3431)
Stop reviving removed meta properties (#3432)
Create docs for building questionnaires (#3393)
feat(@medplum/core) Add `AbortSignal` support to client's `createBinary` and `createAttachment` methods (#3420)
Fixes #3401 - Handle no AWS credentials in AWS init tool (#3418)
Revert "`BinarySource` supporting `ReadableStream` (#3411)" (#3421)
Add bulleted list of SuperAdmin priveleges (#3408)
Add a note that config must be updated locally when making changes (#3410)
Improve linking for using binary data (#3406)
Fixes #3413 - set meta.author when updating access policy (#3419)
`BinarySource` supporting `ReadableStream` (#3411)
Handle non-string code in formatCoding (#3415)
Fixes #3414 - use ESM in example apps (#3416)
Fixes #3389 - add vercel.json config to examples (#3417)
feat(fhircast): add `heartbeat` event (#3350)
Add note about graphql respecting access policies (#3403)
Fixes #3395 - Build scripts handle no git repo (#3400)
Dependency upgrades (#3397)
Add callout for batch vs transaction bundles (#3399)
Fixes #3395 - Build scripts handle no git repo (#3396)
Improve examples in the include search docs (#3359)
QuestionnaireBuilder Autosave (#3253)
chore(package.json): add `private: true` to root (#3390)
Docs: FHIR Profile Creation & Search (#3357)
github-merge-queue bot pushed a commit that referenced this pull request Dec 2, 2023
Fixes #3391 - setup git in preapare-release-yml (#3448)
Create example bots that use a shared code library (#3441)
Fixes #2789 - support 'delete' subscriptions with bots (#3426) (#3445)
Fixes #3391 - github action for prepare-release.sh (#3443)
Revert "Fixes #2789 - support 'delete' subscriptions with bots (#3426)" (#3444)
Update AWS instructions (#3437)
Bump @adobe/css-tools from 4.3.1 to 4.3.2 (#3440)
Fix ValidBot warnings (#3438)
Fixes #3404 - add Referrer-Policy and Permissions-Policy headers (#3436)
Fixes #2789 - support 'delete' subscriptions with bots (#3426)
Agent source cleanup (#3431)
Stop reviving removed meta properties (#3432)
Create docs for building questionnaires (#3393)
feat(@medplum/core) Add `AbortSignal` support to client's `createBinary` and `createAttachment` methods (#3420)
Fixes #3401 - Handle no AWS credentials in AWS init tool (#3418)
Revert "`BinarySource` supporting `ReadableStream` (#3411)" (#3421)
Add bulleted list of SuperAdmin priveleges (#3408)
Add a note that config must be updated locally when making changes (#3410)
Improve linking for using binary data (#3406)
Fixes #3413 - set meta.author when updating access policy (#3419)
`BinarySource` supporting `ReadableStream` (#3411)
Handle non-string code in formatCoding (#3415)
Fixes #3414 - use ESM in example apps (#3416)
Fixes #3389 - add vercel.json config to examples (#3417)
feat(fhircast): add `heartbeat` event (#3350)
Add note about graphql respecting access policies (#3403)
Fixes #3395 - Build scripts handle no git repo (#3400)
Dependency upgrades (#3397)
Add callout for batch vs transaction bundles (#3399)
Fixes #3395 - Build scripts handle no git repo (#3396)
Improve examples in the include search docs (#3359)
QuestionnaireBuilder Autosave (#3253)
chore(package.json): add `private: true` to root (#3390)
Docs: FHIR Profile Creation & Search (#3357)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
communications Features and fixes related to communications
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[FHIRcast] Add heartbeat server-side event
3 participants