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(app-shell-odd): Use sd-notify #12266

Merged
merged 6 commits into from
Mar 15, 2023
Merged

feat(app-shell-odd): Use sd-notify #12266

merged 6 commits into from
Mar 15, 2023

Conversation

sfoster1
Copy link
Member

@sfoster1 sfoster1 commented Mar 10, 2023

Overview

sd-notify is a utility for a program to communicate back to the systemd process manager that started it. It can be used in a variety of ways; the one that is most critical is to positively assert that it has started OK. Since this is a function call you can make any time you want to, this lets your program define when it has "started" on its own terms.

The app, especially on the ODD, takes a long time to start - chrome takes a long time to start, and then we load up all our stuff. Currently, systemd considers us "started" as soon as the shell script that invokes chrome exits, which is long before anything useful is rendered. By making ourselves a notify service (in Opentrons/oe-core#63) and putting the notify at the time we receive the first ipc message, which indicates that the frontend is up, we can delay that "ready" status until we're actually rendering.

This can then be used as a criterion in systemd to take down a loading screen.

TBD

  • Whether this is actually the right place to put the notify
  • Whether it's pointless (or rather there's more work to do) because the app takes over the screen before the notify anyway
  • Whether this catastrophically breaks dev flows on non-linux machines

Test Plan

  • Run normal dev workflows on not-linux and see if it breaks
  • Run on a flex and see if the time that systemd says we're up now matches better with when we start rendering

This is the official npm package for the node bindings of sd_notify,
which is how you tell systemd that you're ready to run.
This will let systemd have a better understanding of when the app is
actually ready.

It's TBD what happens when you do this on something other than a linux
machine where libsystemd is available. We may need a workaround for dev tasks.

Closes RCORE-683
@sfoster1 sfoster1 requested review from a team as code owners March 10, 2023 17:34
@sfoster1 sfoster1 requested review from shlokamin and removed request for a team March 10, 2023 17:34
@codecov
Copy link

codecov bot commented Mar 10, 2023

Codecov Report

Merging #12266 (5940c7f) into edge (10fa3ce) will increase coverage by 0.26%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             edge   #12266      +/-   ##
==========================================
+ Coverage   73.55%   73.81%   +0.26%     
==========================================
  Files        1477     2199     +722     
  Lines       48563    60921   +12358     
  Branches     2980     6341    +3361     
==========================================
+ Hits        35719    44970    +9251     
- Misses      12390    14489    +2099     
- Partials      454     1462    +1008     
Flag Coverage Δ
app 72.28% <0.00%> (+25.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
app-shell-odd/src/main.ts 0.00% <0.00%> (ø)
app-shell-odd/src/systemd.ts 0.00% <0.00%> (ø)

... and 721 files with indirect coverage changes

@sfoster1 sfoster1 added the ot3-build Do an OT-3 system build for this branch. label Mar 10, 2023
Copy link
Member

@shlokamin shlokamin left a comment

Choose a reason for hiding this comment

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

seems reasonable to me

Comment on lines +63 to +65
},
"optionalDependencies": {
"sd-notify": "2.8.0"
Copy link
Member

Choose a reason for hiding this comment

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

shouldnt this be a regular dependency?

Copy link
Member Author

Choose a reason for hiding this comment

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

It won't actually install correctly on not-linux - this is a thin wrapper around system libsystemd

Comment on lines +87 to +88
ipcMain.once('dispatch', () => {
sdNotify.sendStatus('started')
Copy link
Member

Choose a reason for hiding this comment

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

i think this should only send once since its in the startup fn and i assume this gets garbage collected and that event listener stops but we should make sure

Copy link
Member Author

Choose a reason for hiding this comment

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

since it uses once doesn't that mean it'll only be one time?

app-shell-odd/src/systemd.ts Show resolved Hide resolved
@sfoster1 sfoster1 merged commit ab85171 into edge Mar 15, 2023
@sfoster1 sfoster1 deleted the add-sd-notify-to-app branch March 15, 2023 17:33
sfoster1 added a commit that referenced this pull request Mar 16, 2023
This is a fixup of #12266 ( ab85171 ) and more detail can be found there.

This fixes the issue I should have remembered that we really can't use node extensions because they don't get cross-compiled correctly, so now we just shell out to the command-line executable. Requires some different flags (specifically https://github.com/Opentrons/oe-core/pull/63/files#diff-ec32fa0cac503403c1384b437fe44635c404ad5616d1711595f5c4c5b82073b8R14 ) but works fine once you do that.
sfoster1 added a commit to Opentrons/oe-core that referenced this pull request Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ot3-build Do an OT-3 system build for this branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants