Skip to content

Conversation

@meeroslav
Copy link
Contributor

@meeroslav meeroslav commented Sep 2, 2025

Current Behavior

Pre and post hooks lack corellation Id which might make it difficult to culculate stats for task using pre and post hooks.
Additionally, post hook does not expose the duration or time span for the task. Using pre/post hook might not be precise enough.

Expected Behavior

Hooks expose the unique taskId so we can corellate pre hook of a task to the post hook of the same task. Post hook should expose start and end time of the task run.

Related Issue(s)

Resolves discussion 31076

@meeroslav meeroslav self-assigned this Sep 2, 2025
@meeroslav meeroslav requested a review from a team as a code owner September 2, 2025 08:53
@vercel
Copy link

vercel bot commented Sep 2, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Sep 26, 2025 3:13pm

@meeroslav meeroslav changed the title feat(core): add start and end time to post hook and fix docs feat(core): add start and end time to post hook Sep 2, 2025
@nx-cloud
Copy link
Contributor

nx-cloud bot commented Sep 2, 2025

View your CI Pipeline Execution ↗ for commit e409e9e

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 43m 16s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 1m 49s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 5s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 4s View ↗
nx documentation ✅ Succeeded 1m 28s View ↗

☁️ Nx Cloud last updated this comment at 2025-09-26 15:47:46 UTC

@@ -1,5 +1,5 @@
import type { ProjectGraph } from '../../config/project-graph';
import { readNxJson, type PluginConfiguration } from '../../config/nx-json';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are unused

groupId: number;
}

interface RustRunningTask extends RunningTask {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was unused

@meeroslav meeroslav added the scope: core core nx functionality label Sep 8, 2025
Copy link
Collaborator

@FrozenPandaz FrozenPandaz left a comment

Choose a reason for hiding this comment

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

This seems very easy to get if users run Date.now() in their pre and post hooks. I don't think we need to be the one providing this.

@meeroslav
Copy link
Contributor Author

This seems very easy to get if users run Date.now() in their pre and post hooks. I don't think we need to be the one providing this.

@FrozenPandaz, it might not be trivial when you run several commands in parallel. Providing this information out of the box instead of forcing the user to track the collection of start times in memory per args combo is better, in my opinion. Also, it prevents other (potentially long-running) Pre and Post hooks from skewing the numbers.

].join('\n')}\n`
);
}
const taskId = hashArray([...process.argv, Date.now().toString()]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please call this a tasksExecutionId or executionId... or even just id. Just definitely not task.id

};

export type PreTasksExecutionContext = {
readonly taskId: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can make this just id

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it to just id.

import { shouldStreamOutput } from './utils';
import { signalToCode } from '../utils/exit-codes';
import chalk = require('chalk');
import { randomUUID } from 'node:crypto';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't look to be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, AI autocomplete leftover. Let me kick that out.

@meeroslav meeroslav changed the title feat(core): add start and end time to post hook feat(core): add id, start and end time to lifecycle hooks Sep 26, 2025
@meeroslav meeroslav merged commit 05227d7 into master Sep 26, 2025
16 checks passed
@meeroslav meeroslav deleted the feat/add-time-to-post-hook branch September 26, 2025 15:55
@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2025

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

scope: core core nx functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants