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

Allow running cli commands without db connection #235

Closed
spencewenski opened this issue Jun 22, 2024 · 7 comments · Fixed by #353
Closed

Allow running cli commands without db connection #235

spencewenski opened this issue Jun 22, 2024 · 7 comments · Fixed by #353
Labels
enhancement New feature or request
Milestone

Comments

@spencewenski
Copy link
Member

Creating the app context requires connecting to the db (if a db feature is enabled). If no db is running, the cli will not run. We have a couple options:

  1. Can we create the db connection pool (sql, redis, etc) without needing for it to be able to actually connect to the db?
  2. If (1) is not possible, we can add a method to the RunCommand trait that runs right after the app config is parsed (and tracing is initialized) and before the app context is created.
@spencewenski spencewenski added this to the 0.3.x milestone Jun 22, 2024
@spencewenski
Copy link
Member Author

This can also impact commands implemented by services, eg, the openapi command. It would be good if the openapi command could be run without needing to start the db

@spencewenski spencewenski added the enhancement New feature or request label Jun 22, 2024
@spencewenski
Copy link
Member Author

Can we create the db connection pool (sql, redis, etc) without needing for it to be able to actually connect to the db?

I don't think this is currently possible with seaorm, but I think it is with sqlx, so we may be able to submit a PR to seaorm to enable this behavior.

@spencewenski spencewenski changed the title Allow running cli commands without app context Allow running cli commands without db connection Jun 22, 2024
@spencewenski
Copy link
Member Author

Opened a PR on SEA ORM: SeaQL/sea-orm#2268

@spencewenski
Copy link
Member Author

For redis/sidekiq, we need to move the "stale cleanup" behavior out of the "build" method so it runs after the service is built and after the "handle cli" method is run against the services.

@spencewenski
Copy link
Member Author

This should be a quick fix once SeaQL/sea-orm#2268 is merged.

@spencewenski
Copy link
Member Author

The seaorm team is taking a while to look at the proposed pr above.

An alternative could be to use a OnceLock to lazy init the db connection?

@spencewenski
Copy link
Member Author

Hmm, the problem with OnceLock is the db connection creation can return an error, so we would need to add a layer of checks everywhere the db connection is requested.

@spencewenski spencewenski modified the milestones: 0.3.x, 0.5.x Jul 2, 2024
@spencewenski spencewenski modified the milestones: 0.5.x, 0.6.x Aug 25, 2024
spencewenski added a commit that referenced this issue Aug 28, 2024
Sea-orm added support for lazy database connections. We provide a config
field to allow toggling lazy database connections on or off. If lazy
connections are enabled, the default `run` method will allow running CLI
commands without requiring the the DB connection to be available (unless
the CLI command itself attempts to execute a DB query).

Closes #235
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant