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

chore: type improvement for schedulers #6136

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gastonfournier
Copy link
Contributor

About the changes

Closes #

Important files

Discussion points

Copy link

vercel bot commented Feb 6, 2024

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

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Feb 6, 2024 8:11am
unleash-monorepo-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 6, 2024 8:11am

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Code Health Quality Gates: OK

  • Declining Code Health: 1 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Lightweight sanity check
View detailed results in CodeScene

🚩 Declining Code Health (highest to lowest):

@@ -48,6 +48,7 @@ export const scheduleServices = async (
apiTokenService.fetchActiveTokens.bind(apiTokenService),
minutesToMilliseconds(1),
'fetchActiveTokens',
0, // no jitter -> run immediately

Choose a reason for hiding this comment

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

❌ Getting worse: Large Method
scheduleServices increases from 135 to 136 lines of code, threshold = 70

Why does this problem occur?

Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function. Read more.

To ignore this warning click here.

() => {
clientMetricsServiceV2.bulkAdd().catch(console.error);
async () => {
await clientMetricsServiceV2.bulkAdd().catch(console.error);
Copy link
Contributor

@kwasniew kwasniew Feb 6, 2024

Choose a reason for hiding this comment

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

() => clientMetricsServiceV2.bulkAdd().catch(console.error); is almost the same since the last statement and returns Promise. The main difference is that it returns Promise with results value and not just Promise

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but there's no return... I could add one, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

In general it's more idiomatic to do () => Promise.resolve() over async () => { await Promise.resolve(); }

Copy link
Contributor

Choose a reason for hiding this comment

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

() => Promise.resolve() returns the promise when you don't add {} around it

Copy link
Contributor

Choose a reason for hiding this comment

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

() => Promise.resolve() is more idiomatic than () => { return Promise.resolve() }

() => {
clientMetricsServiceV2.clearMetrics(48).catch(console.error);
async () => {
await clientMetricsServiceV2.clearMetrics(48).catch(console.error);
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

Copy link
Contributor

@kwasniew kwasniew left a comment

Choose a reason for hiding this comment

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

Is there any particular problem you're trying to solve here?

@gastonfournier
Copy link
Contributor Author

Is there any particular problem you're trying to solve here?

I saw we were making an await on a function that didn't return a promise, so I thought maybe there's something off that's causing our scheduled jobs to pile up. So I wanted to change the type to find out that, but I don't think there's something...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Approved PRs
Development

Successfully merging this pull request may close these issues.

None yet

2 participants