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: making the scheduler db not rely on env vars #2171

Merged
merged 1 commit into from
May 21, 2024

Conversation

TBonnin
Copy link
Collaborator

@TBonnin TBonnin commented May 17, 2024

Describe your changes

configuring the scheduler, which is a independant library, with env vars make it harder to understand where things are being configured and how. We ran into issues with the records package regarding default env vars value and behavior if/when not configured. With this commit the db url and schema are passed into the scheduler package and we don't have a global db object within the package. The Tasks function are now all taking db as their first parameter, this has the nice side effect to make it possible to run them in a transaction if needed.

Checklist before requesting a review (skip if just adding/editing APIs & templates)

  • I added tests, otherwise the reason is:
  • I added observability, otherwise the reason is:
  • I added analytics, otherwise the reason is:

if (!url || !schema) {
throw new Error('Missing required database url and schema for monitor worker');
}
const dbClient = new DatabaseClient({ url, schema, poolMax: 10 });
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the worker thread doesn't share anything with the main thread and only serializable object can be messaged between them so we are creating another db client for the worker thread. Right now the worker is only expiring tasks but when we add support for recurring tasks the worker will be responsible for all state transitions not trigger by an event

@TBonnin TBonnin force-pushed the tbonnin/scheduler-db-params branch 3 times, most recently from 90b247a to 2e6575f Compare May 20, 2024 21:02
configuring the scheduler, which is a independant library, with env vars
make it harder to understand where things are being configured and how.
We ran into issues with the records package regarding default
env vars value and behavior if/when not configured.
With this commit the db url and schema are passed into the scheduler
package and we don't have a global db object within the package.
The `Tasks` function are now all taking `db` as their first parameter,
this has the nice side effect to make it possible to run them in a
transaction if needed.
@TBonnin TBonnin force-pushed the tbonnin/scheduler-db-params branch from 2e6575f to 81fa54c Compare May 21, 2024 12:33
@TBonnin TBonnin enabled auto-merge (squash) May 21, 2024 12:33
@TBonnin TBonnin disabled auto-merge May 21, 2024 12:42
@TBonnin TBonnin merged commit cf147d7 into master May 21, 2024
21 checks passed
@TBonnin TBonnin deleted the tbonnin/scheduler-db-params branch May 21, 2024 13:10
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.

None yet

3 participants