Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ui/src/components/run/run-logs-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</span>
<span
v-else-if="['warning', 'info', 'debug'].includes(log.type)"
:class="log.type === 'warning' ? 'text-info' : ''"
:class="logTextClass(log)"
>
{{ log.msg }}
</span>
Expand Down Expand Up @@ -65,6 +65,12 @@ const taskColor = (log: LogEntry) => {
return 'primary'
}

const logTextClass = (log: LogEntry) => {
if (log.type === 'warning') return 'text-warning'
if (log.type === 'debug') return 'text-medium-emphasis'
return ''
}

const formatDate = (date: string) => dayjs(date).format('lll')
</script>

Expand Down
19 changes: 15 additions & 4 deletions worker/src/task/memory-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { formatMem, type MemorySample, type MemorySamplePhase } from '../utils/m

type DebugLog = (msg: string, extra?: string) => Promise<void>

const MEMORY_LOG_LABEL = 'Task process memory stats'

const buildSample = (phase: MemorySamplePhase): MemorySample => {
const m = process.memoryUsage()
return {
Expand All @@ -22,15 +24,19 @@ const writeStdoutSample = (sample: MemorySample): void => {
}

export type MemoryReporterHandle = {
stop: () => void
stop: () => Promise<void>
}

export const startMemoryReporter = (
processing: Processing,
debug: DebugLog,
intervalMs: number
): MemoryReporterHandle => {
writeStdoutSample(buildSample('startup'))
const startupSample = buildSample('startup')
writeStdoutSample(startupSample)
if (processing.debug) {
debug(`${MEMORY_LOG_LABEL} - ${formatMem(startupSample)}`).catch(() => { /* best-effort */ })
}

let timer: NodeJS.Timeout | null = null
if (intervalMs > 0) {
Expand All @@ -40,7 +46,7 @@ export const startMemoryReporter = (
if (processing.debug) {
// Skip building the debug string when debug is off
// (log.debug also no-ops, but avoids formatMem cost).
debug('memory', formatMem(sample)).catch(() => { /* best-effort */ })
debug(`${MEMORY_LOG_LABEL} - ${formatMem(sample)}`).catch(() => { /* best-effort */ })
}
}, intervalMs)
timer.unref()
Expand All @@ -53,9 +59,14 @@ export const startMemoryReporter = (
process.on('exit', onExit)

return {
stop: () => {
stop: async () => {
if (timer) { clearInterval(timer); timer = null }
process.off('exit', onExit)
const exitSample = buildSample('exit')
writeStdoutSample(exitSample)
if (processing.debug) {
await debug(`${MEMORY_LOG_LABEL} - ${formatMem(exitSample)}`).catch(() => { /* best-effort */ })
}
}
}
}
3 changes: 2 additions & 1 deletion worker/src/task/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const run = async (mailTransport: any) => {
log.warn = log.warning // for compatibility with old plugins
// Start memory sampler: emits df-mem: lines on stdout for parent metrics,
// and (when processing.debug) appends debug entries to run.log.
startMemoryReporter(processing, log.debug, config.worker.task.memorySampleIntervalMs)
const memReporter = startMemoryReporter(processing, log.debug, config.worker.task.memorySampleIntervalMs)
if (run.status === 'running') {
await log.step('Reprise après interruption.')
}
Expand Down Expand Up @@ -196,6 +196,7 @@ export const run = async (mailTransport: any) => {
}
return err
} finally {
await memReporter.stop()
try {
await tmpDir.cleanup()
} catch (err) {
Expand Down
Loading