@output.ai/core 0.1.8-dev.pr156.ac53caf → 0.1.8-dev.pr156.f70e0a1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -4,56 +4,66 @@ import { fileURLToPath } from 'url';
|
|
|
4
4
|
import buildTraceTree from '../../tools/build_trace_tree.js';
|
|
5
5
|
import { EOL } from 'node:os';
|
|
6
6
|
|
|
7
|
-
const oneWeekInMS = 1000 * 60 * 60 * 24 * 7;
|
|
8
7
|
const __dirname = dirname( fileURLToPath( import.meta.url ) );
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
const PURGE_TEMP_FILES_THRESHOLD = 1000 * 60 * 60 * 24 * 7; // 1 week in milliseconds
|
|
10
|
+
|
|
11
|
+
// The path to the project root
|
|
12
|
+
const LOCAL_PROJECT_ROOT_PATH = process.argv[2] || process.cwd();
|
|
13
|
+
|
|
14
|
+
// The path to the local trace logs
|
|
15
|
+
const LOCAL_TRACE_LOG_PATH = join( LOCAL_PROJECT_ROOT_PATH, 'logs' );
|
|
16
|
+
|
|
17
|
+
// The path to the temporary trace logs
|
|
18
|
+
const TMP_TRACE_LOG_PATH = join( __dirname, 'temp', 'traces' );
|
|
10
19
|
|
|
11
20
|
const accumulate = ( { entry, executionContext: { workflowId, startTime } } ) => {
|
|
12
|
-
const path = join(
|
|
21
|
+
const path = join( TMP_TRACE_LOG_PATH, `${startTime}_${workflowId}.trace` );
|
|
13
22
|
appendFileSync( path, JSON.stringify( entry ) + EOL, 'utf-8' );
|
|
14
23
|
return readFileSync( path, 'utf-8' ).split( EOL ).slice( 0, -1 ).map( v => JSON.parse( v ) );
|
|
15
24
|
};
|
|
16
25
|
|
|
17
|
-
const cleanupOldTempFiles = ( threshold = Date.now() -
|
|
18
|
-
readdirSync(
|
|
26
|
+
const cleanupOldTempFiles = ( threshold = Date.now() - PURGE_TEMP_FILES_THRESHOLD ) =>
|
|
27
|
+
readdirSync( TMP_TRACE_LOG_PATH )
|
|
19
28
|
.filter( f => +f.split( '_' )[0] < threshold )
|
|
20
|
-
.forEach( f => rmSync( join(
|
|
29
|
+
.forEach( f => rmSync( join( TMP_TRACE_LOG_PATH, f ) ) );
|
|
21
30
|
|
|
22
31
|
/**
|
|
23
|
-
*
|
|
32
|
+
* Get the host trace log path, which is used for reporting trace locations.
|
|
33
|
+
* In containerized environments (e.g., Docker), this can be different from the local path
|
|
34
|
+
* to map container paths to host filesystem paths.
|
|
35
|
+
* @returns {string} The host trace log path from HOST_TRACE_PATH env var, or local path as fallback
|
|
24
36
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
cleanupOldTempFiles();
|
|
37
|
+
const getHostTraceLogPath = () => {
|
|
38
|
+
return process.env.HOST_TRACE_PATH || LOCAL_TRACE_LOG_PATH;
|
|
28
39
|
};
|
|
29
40
|
|
|
30
41
|
/**
|
|
31
|
-
*
|
|
32
|
-
* Always writes to the local working directory, regardless of HOST_TRACE_PATH
|
|
33
|
-
* @returns {string} The base path where traces should be written in the container
|
|
42
|
+
* Init this processor
|
|
34
43
|
*/
|
|
35
|
-
const
|
|
36
|
-
|
|
44
|
+
export const init = () => {
|
|
45
|
+
mkdirSync( TMP_TRACE_LOG_PATH, { recursive: true } );
|
|
46
|
+
cleanupOldTempFiles();
|
|
37
47
|
};
|
|
38
48
|
|
|
39
49
|
/**
|
|
40
|
-
* Get the
|
|
41
|
-
* Uses
|
|
42
|
-
* @
|
|
50
|
+
* Get the local file system path for ALL file I/O operations (read/write)
|
|
51
|
+
* Uses the project root path passed as argv[2], falls back to cwd
|
|
52
|
+
* @param {string} workflowName - The name of the workflow
|
|
53
|
+
* @returns {string} The local filesystem path for file operations
|
|
43
54
|
*/
|
|
44
|
-
const
|
|
45
|
-
return
|
|
55
|
+
const getLocalOutputDir = workflowName => {
|
|
56
|
+
return join( LOCAL_PROJECT_ROOT_PATH, 'logs', 'runs', workflowName );
|
|
46
57
|
};
|
|
47
58
|
|
|
48
59
|
/**
|
|
49
|
-
* Get the
|
|
60
|
+
* Get the host path for reporting trace file locations to users
|
|
61
|
+
* Uses HOST_TRACE_PATH if set (for Docker), otherwise uses project root
|
|
50
62
|
* @param {string} workflowName - The name of the workflow
|
|
51
|
-
* @
|
|
52
|
-
* @returns {string} The output directory path
|
|
63
|
+
* @returns {string} The path to report to users/API
|
|
53
64
|
*/
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
return join( basePath, 'runs', workflowName );
|
|
65
|
+
const getReportOutputDir = workflowName => {
|
|
66
|
+
return join( getHostTraceLogPath(), 'runs', workflowName );
|
|
57
67
|
};
|
|
58
68
|
|
|
59
69
|
const buildOutputFileName = ( { startTime, workflowId } ) => {
|
|
@@ -75,8 +85,8 @@ export const exec = ( { entry, executionContext } ) => {
|
|
|
75
85
|
const { workflowId, workflowName, startTime } = executionContext;
|
|
76
86
|
const content = buildTraceTree( accumulate( { entry, executionContext } ) );
|
|
77
87
|
|
|
78
|
-
//
|
|
79
|
-
const dir =
|
|
88
|
+
// Always use local path for writing files
|
|
89
|
+
const dir = getLocalOutputDir( workflowName );
|
|
80
90
|
const path = join( dir, buildOutputFileName( { startTime, workflowId } ) );
|
|
81
91
|
|
|
82
92
|
mkdirSync( dir, { recursive: true } );
|
|
@@ -92,5 +102,6 @@ export const exec = ( { entry, executionContext } ) => {
|
|
|
92
102
|
* @returns {string} The absolute path where the trace will be saved
|
|
93
103
|
*/
|
|
94
104
|
export const getDestination = ( { startTime, workflowId, workflowName } ) => {
|
|
95
|
-
|
|
105
|
+
// Use report path for reporting to users/API
|
|
106
|
+
return join( getReportOutputDir( workflowName ), buildOutputFileName( { workflowId, startTime } ) );
|
|
96
107
|
};
|
|
@@ -40,6 +40,7 @@ describe( 'tracing/processors/local', () => {
|
|
|
40
40
|
|
|
41
41
|
init();
|
|
42
42
|
|
|
43
|
+
// Should create temp dir relative to module location using __dirname
|
|
43
44
|
expect( mkdirSyncMock ).toHaveBeenCalledWith( expect.stringMatching( /temp\/traces$/ ), { recursive: true } );
|
|
44
45
|
expect( rmSyncMock ).toHaveBeenCalledTimes( 1 );
|
|
45
46
|
} );
|