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

Service installs: Avoid creating duplicate tasks on device registration #1867

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

thgreasi
Copy link
Member

Change-type: patch

@thgreasi thgreasi requested a review from a team November 27, 2024 21:52
const addSystemAppServiceInstallHooks = (
fieldName: 'should_be_managed_by__release' | 'should_be_operated_by__release',
) => {
hooks.addPureHook('POST', 'resin', 'device', {
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved this higher, in the hooks.addPureHook('POST', 'resin', 'device') that we have for user apps.

// creates all service installs (target release, hostApp & SV release), so we don't need
// to run the extra code bellow to handle them separately, and doing so would create
// duplicate & unecessary tasks.
return;
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 I expect that soon tasks will become the only supported way for creating service installs, I decided to fix this in the simplest way that required the less changes in the current code.

if (ASYNC_TASKS_ENABLED && ASYNC_TASK_CREATE_SERVICE_INSTALLS_ENABLED) {
// When creating service installs via the async tasks, a single call to createServiceInstallsAsync()
// creates all service installs (target release, hostApp & SV release), so we don't need
// to run the extra code bellow to handle them separately, and doing so would create
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// to run the extra code bellow to handle them separately, and doing so would create
// to run the extra code below to handle them separately, and doing so would create

Copy link
Member Author

Choose a reason for hiding this comment

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

TIL what that means XD

// When creating service installs via the async tasks, a single call to createServiceInstallsAsync()
// creates all service installs (target release, hostApp & SV release), so we don't need
// to run the extra code bellow to handle them separately, and doing so would create
// duplicate & unecessary tasks.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// duplicate & unecessary tasks.
// duplicate & unnecessary tasks.

@@ -260,6 +260,13 @@ hooks.addPureHook('POST', 'resin', 'device', {
const app = request.values.belongs_to__application;
if (app != null) {
await createAppServiceInstalls(rootApi, app, [deviceId], tx);
if (ASYNC_TASKS_ENABLED && ASYNC_TASK_CREATE_SERVICE_INSTALLS_ENABLED) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't ASYNC_TASK_CREATE_SERVICE_INSTALLS_ENABLED only ever equal true if ASYNC_TASKS_ENABLED is also true? Maybe there was a discussion about this at some point, but I feel like system init should fail if ASYNC_TASKS_ENABLED === false && ASYNC_TASK_CREATE_SERVICE_INSTALLS_ENABLED === true.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea I agree on that this was strange. I expected it to only have to check one of the two, maybe something like:

export let ASYNC_TASK_CREATE_SERVICE_INSTALLS_ENABLED = ASYNC_TASKS_ENABLED && boolVar(
	'ASYNC_TASK_CREATE_SERVICE_INSTALLS_ENABLED',
	false,
);

But since I don't have background on why it was done this way, I just copied it "as is" from above where we do the same check. I guess that it might be this way to make mocking in tests easier. I would prefer to PR such a change separately and fix all occurrences and whichever tests might break after having a short chat on it.

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