-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
2.x.x - Run process before server start #340
Conversation
let router = HBRouter() | ||
var app = HBApplication( | ||
responder: router.buildResponder() | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once #339 is merged I can add a check to see if the atomic has been set by then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#339 can be merged
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## 2.x.x #340 +/- ##
==========================================
+ Coverage 83.08% 83.27% +0.18%
==========================================
Files 92 93 +1
Lines 5037 5058 +21
==========================================
+ Hits 4185 4212 +27
+ Misses 852 846 -6 ☔ View full report in Codecov by Sentry. |
Pull request benchmark comparison [ubuntu-latest] with '2.x.x' run at 2024-01-11T07:12:23+00:00 |
var services: [any Service] { self.base.services } | ||
|
||
/// Processes run before server start | ||
public var processesRunBeforeServerStart: [@Sendable () async throws -> Void] { self.base.processesRunBeforeServerStart } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this variable name, but I don't know a better one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could use pre
. Like preStartProcesses
. A little bit more vague than processesRunBeforeServerStart
, but should do the job.
In that case, there is also the runBeforeServerStart
function that needs to have a change of name to something like preStartRun
. Not sure if these are the best options, but they sound good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's not a great variable name, but I don't think @MahdiBM your suggestions are much better especially the function rename. preStartRun
doesn't mean a great deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gonna add a Bikeshedding issue with all the symbol names that need revisiting and add this to it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do fix the test, but otherwise approved
let router = HBRouter() | ||
var app = HBApplication( | ||
responder: router.buildResponder() | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#339 can be merged
var services: [any Service] { self.base.services } | ||
|
||
/// Processes run before server start | ||
public var processesRunBeforeServerStart: [@Sendable () async throws -> Void] { self.base.processesRunBeforeServerStart } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could use pre
. Like preStartProcesses
. A little bit more vague than processesRunBeforeServerStart
, but should do the job.
In that case, there is also the runBeforeServerStart
function that needs to have a change of name to something like preStartRun
. Not sure if these are the best options, but they sound good to me.
Co-authored-by: Mahdi Bahrami <github@mahdibm.com>
Also added testOnServerRunning
7339956
to
3de1cd5
Compare
While writing the Todos tutorial I came across an issue with database setup. There are situations where you need to do pre-processing of your database before starting the server eg running migrations. Unfortunately the new PostgresClient requires that you have a background process running, not currently managed by ServiceLifecycle but I assume it will be eventually. So you can't do the database preprocessing before the server has started because it requires the PostgresClient service to be running, which would also kick off the server service.
This PR adds a way to add processes to be run before the server has started but while all other services are running.