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

refactor(core): Centralize CronJob management #10033

Merged
merged 20 commits into from
Jul 16, 2024
Merged

Conversation

netroy
Copy link
Member

@netroy netroy commented Jul 12, 2024

Summary

Letting individual nodes manage CronJob

  1. creates a lot of duplicate code
  2. adds the responsibility of cleaning up on the nodes
  3. doesn't give us a centralized overview of all active CronJobs in the process

This PR aims to centralize how we register cronJobs, to have a better control over their lifecycle.

Review / Merge checklist

  • PR title and summary are descriptive
  • Tests included

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team node/improvement New feature or request labels Jul 12, 2024
@netroy netroy marked this pull request as ready for review July 15, 2024 07:11
});
});

describe.only('recurrenceCheck', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

@ivov any idea why this did not get caught by the linter?

Copy link
Contributor

Choose a reason for hiding this comment

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

Likely we need to update the first path in this line to '**/test/**/*.ts'. Or have nodes-base start using the pattern from other packages: **/__tests__/*.ts

@netroy netroy requested review from elsmr and ivov July 15, 2024 11:44
despairblue
despairblue previously approved these changes Jul 16, 2024
packages/core/src/ScheduledTaskManager.ts Outdated Show resolved Hide resolved
packages/core/src/ScheduledTaskManager.ts Outdated Show resolved Hide resolved
packages/workflow/src/Interfaces.ts Outdated Show resolved Hide resolved
packages/core/src/ActiveWorkflows.ts Show resolved Hide resolved
packages/workflow/src/Interfaces.ts Show resolved Hide resolved
Copy link

cypress bot commented Jul 16, 2024

4 flaky tests on run #5961 ↗︎

0 400 0 0 Flakiness 4

Details:

🌳 master 🖥️ browsers:node18.12.0-chrome107 🤖 PR User 🗃️ e2e/*
Project: n8n Commit: 09f2cf9eaf
Status: Passed Duration: 05:17 💡
Started: Jul 17, 2024 3:11 AM Ended: Jul 17, 2024 3:16 AM
Flakiness  10-undo-redo.cy.ts • 1 flaky test

View Output Video

Test Artifacts
Undo/Redo > should undo/redo adding connected nodes Test Replay Screenshots Video
Flakiness  5-ndv.cy.ts • 2 flaky tests

View Output Video

Test Artifacts
NDV > should not retrieve remote options when required params throw errors Screenshots Video
NDV > Stop listening for trigger event from NDV Screenshots Video
Flakiness  24-ndv-paired-item.cy.ts • 1 flaky test

View Output Video

Test Artifacts
NDV > resolves expression with default item when input node is not parent, while still pairing items Test Replay Screenshots Video

Review all test suite changes for PR #10033 ↗︎

Copy link
Contributor

✅ All Cypress E2E specs passed

@despairblue despairblue removed the request for review from ivov July 16, 2024 10:34
}
const fallbackToZero = addFallbackValue(nodeVersion >= 1.2, '0');
Copy link
Contributor

Choose a reason for hiding this comment

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

This was introduced to fix a behavior for schedule nodes version 1.2 and above.
For version 1.0 and 1.1 if you set triggerAtMinute to an empty string it will run every minute, as opposed to every hour/day/week, etc.

This was fixed here: #9146
The fix added the version 1.2 and only applied to that and following versions. I'm assuming this was done so that it would not break users that rely on the buggy behavior.

With this refactor we apply the "fixed" behavior to all versions now. Which is technically a breaking change.

@Joffcom sorry for looping you in here out of the blue, but maybe you have some insight if we can assume that this will break some workflows in the wild or if we can just "fix" it for all versions?

cc @michael-radency

Copy link
Contributor

Choose a reason for hiding this comment

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

@despairblue correct, changes that could be breaking are usually scoped under version, if it's not bugfix
we need to update packages/cli/BREAKING-CHANGES.md in this case

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm gonna try to add the check back, and also add tests to prevent this from breaking in the future 🤞🏽

Copy link
Member Author

Choose a reason for hiding this comment

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

For version 1.0 and 1.1 if you set triggerAtMinute to an empty string it will run every minute, as opposed to every hour/day/week, etc.

When I try this on older versions of the node, the Cron expression that's generated is ' * * * *', which in an invalid expression.
@michael-radency do you recall why did we decide to support this old behavior?
IMO, this is bug, and shouldn't have been supported. All versions of this node should fallback to 0 when the field is an empty string.

Copy link
Member Author

@netroy netroy Jul 16, 2024

Choose a reason for hiding this comment

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

In the new code now if a user leaves the minute empty, we generate a valid cron expression by falling back to a random minute during activation.

I'm still not sure why we created a new version in #9146.
I believe this was a bug, and we should have fixed this in the existing version of the node.
If user is adding invalid values in any of the fields, then we don't owe them backward compatibility, nor do we need to document this as a breaking change.

IMO the changes proposed in this PR are backward compatible for anyone using this node as intended, for everyone else when the minute field is left invalid, falling back to selecting a random minute during activation works fine.

@netroy netroy requested a review from despairblue July 16, 2024 17:11
Copy link
Contributor

⚠️ Some Cypress E2E specs are failing, please fix them before merging

Copy link
Contributor

✅ All Cypress E2E specs passed

@netroy netroy merged commit 09f2cf9 into master Jul 16, 2024
30 checks passed
@netroy netroy deleted the global-registry-cron branch July 16, 2024 18:42
@janober
Copy link
Member

janober commented Jul 17, 2024

Got released with [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team node/improvement New feature or request Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants