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

Some small cleanup changes pulled out of the quiet logger PR #838

Merged
merged 5 commits into from
Aug 30, 2023
Merged

Conversation

rictic
Copy link
Member

@rictic rictic commented Aug 30, 2023

#836 is way too big, this pulls some of the incidental improvements out of it so they can be reviewed in isolation

Adds some more events, logs them more consistently, puts the logger in control of how it's wrapped when in watch mode.
Copy link
Collaborator

@AndrewJakubowicz AndrewJakubowicz left a comment

Choose a reason for hiding this comment

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

Nice!

@@ -2,6 +2,6 @@
"javascript.preferences.importModuleSpecifierEnding": "js",
"typescript.preferences.importModuleSpecifierEnding": "js",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"typescript.tsdk": "node_modules\\typescript\\lib",
"typescript.tsdk": "node_modules/typescript/lib",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this impact Windows users?

Copy link
Member Author

Choose a reason for hiding this comment

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

Often / works everywhere but \ only works on Windows. If it does then we could likely remove this by then

src/analyzer.ts Outdated
Comment on lines 213 to 216
let rootScriptConfig = undefined;
if (analyzeResult.config.ok) {
rootScriptConfig = analyzeResult.config.value;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is very nice. What do you think about inlining this as a ternary in value position of rootScriptConfig? Then you can skip this if there isn't a logger.

Although it may be a bit less readable. Up to you.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I like htat!

src/event.ts Outdated
Comment on lines 391 to 394
/**
* The analysis phase for an execution has begun, where we load package.json
* files, analyze their wireit configs, and build the dependency graph.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Update to reflect completion of analysis.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! Done

this._logger.log({
script: this._config,
type: 'info',
detail: 'service-process-started',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Is it worth reflecting the state names in detail? E.g., service-process-starting?

Copy link
Member Author

Choose a reason for hiding this comment

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

Starting makes sense to the internal state machine of ServiceScriptExecution, but for everywhere else at this point we have a child process now, so the process has started.

@@ -262,6 +262,15 @@ export class ServiceScriptExecution extends BaseExecutionWithCommand<ServiceScri
entireExecutionAborted,
adoptee,
};
// Doing this here ensures that we always log when the
// service stops, no matter how that happens.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are there other conditions outside the stopping and failing states that could be missed otherwise?

I do like hanging this off the promise.

edit: is child.kill({force: true}); one of these additional cases that are now handled?

Copy link
Member Author

Choose a reason for hiding this comment

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

Before this change we'd only log that it stopped if we stopped it outselves and it was in certain specific states. This way, no matter how it dies (e.g. it chooses to call process.exit()), we inform the logger about it.

@@ -31,7 +31,7 @@ interface EventBase<T extends PackageReference = ScriptReference> {
// Success events
// -------------------------------

type Success = ExitZero | NoCommand | Fresh | Cached;
export type Success = ExitZero | NoCommand | Fresh | Cached;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit, when exporting should add a jsdoc comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

src/logging/default-logger.ts Show resolved Hide resolved
@@ -318,7 +322,11 @@ class ExecResult {
// own process group. Passing the negative of the child's pid kills all
// processes in the group (without the negative only the leader "sh"
// process would be killed).
process.kill(-this._child.pid, 'SIGINT');
if (force) {
process.kill(-this._child.pid, 9);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: thoughts about using 'SIGKILL' instead of the number?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that seems better

src/event.ts Outdated

/**
* A service started running and if it has a readyWhen condition,
* that condition is met.
*/
export interface ServiceStarted extends InfoBase {
detail: 'service-started';
Copy link
Member

Choose a reason for hiding this comment

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

How about renaming this old event to service-ready, to distinguish it more clearly from service-process-started? The "ready" terminology is what we use in the configuration file and docs to mean that the ready condition, if there is one, has been satisfied (e.g. "Server started" was logged).

Copy link
Member Author

Choose a reason for hiding this comment

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

+1, done. Also logged [serviceName] Service ready in the default logger instead of [serviceName] Service started

@rictic rictic enabled auto-merge (squash) August 30, 2023 05:39
@rictic rictic merged commit a7c4a1c into main Aug 30, 2023
22 checks passed
@rictic rictic deleted the quiet-prep branch August 30, 2023 06:02
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.

3 participants