@@ -19,6 +19,7 @@ import { checkUsageStatus } from '@/lib/billing/calculations/usage-monitor'
1919import { getHighestPrioritySubscription } from '@/lib/billing/core/subscription'
2020import { RateLimiter } from '@/lib/core/rate-limiter'
2121import { decryptSecret } from '@/lib/core/security/encryption'
22+ import { formatDuration } from '@/lib/core/utils/formatting'
2223import { getBaseUrl } from '@/lib/core/utils/urls'
2324import type { TraceSpan , WorkflowExecutionLog } from '@/lib/logs/types'
2425import { sendEmail } from '@/lib/messaging/email/mailer'
@@ -227,12 +228,6 @@ async function deliverWebhook(
227228 }
228229}
229230
230- function formatDuration ( ms : number ) : string {
231- if ( ms < 1000 ) return `${ ms } ms`
232- if ( ms < 60000 ) return `${ ( ms / 1000 ) . toFixed ( 1 ) } s`
233- return `${ ( ms / 60000 ) . toFixed ( 1 ) } m`
234- }
235-
236231function formatCost ( cost ?: Record < string , unknown > ) : string {
237232 if ( ! cost ?. total ) return 'N/A'
238233 const total = cost . total as number
@@ -302,7 +297,7 @@ async function deliverEmail(
302297 workflowName : payload . data . workflowName || 'Unknown Workflow' ,
303298 status : payload . data . status ,
304299 trigger : payload . data . trigger ,
305- duration : formatDuration ( payload . data . totalDurationMs ) ,
300+ duration : formatDuration ( payload . data . totalDurationMs , { precision : 1 } ) ?? '-' ,
306301 cost : formatCost ( payload . data . cost ) ,
307302 logUrl,
308303 alertReason,
@@ -315,7 +310,7 @@ async function deliverEmail(
315310 to : subscription . emailRecipients ,
316311 subject,
317312 html,
318- text : `${ subject } \n${ alertReason ? `\nReason: ${ alertReason } \n` : '' } \nWorkflow: ${ payload . data . workflowName } \nStatus: ${ statusText } \nTrigger: ${ payload . data . trigger } \nDuration: ${ formatDuration ( payload . data . totalDurationMs ) } \nCost: ${ formatCost ( payload . data . cost ) } \n\nView Log: ${ logUrl } ${ includedDataText } ` ,
313+ text : `${ subject } \n${ alertReason ? `\nReason: ${ alertReason } \n` : '' } \nWorkflow: ${ payload . data . workflowName } \nStatus: ${ statusText } \nTrigger: ${ payload . data . trigger } \nDuration: ${ formatDuration ( payload . data . totalDurationMs , { precision : 1 } ) ?? '-' } \nCost: ${ formatCost ( payload . data . cost ) } \n\nView Log: ${ logUrl } ${ includedDataText } ` ,
319314 emailType : 'notifications' ,
320315 } )
321316
@@ -373,7 +368,10 @@ async function deliverSlack(
373368 fields : [
374369 { type : 'mrkdwn' , text : `*Status:*\n${ payload . data . status } ` } ,
375370 { type : 'mrkdwn' , text : `*Trigger:*\n${ payload . data . trigger } ` } ,
376- { type : 'mrkdwn' , text : `*Duration:*\n${ formatDuration ( payload . data . totalDurationMs ) } ` } ,
371+ {
372+ type : 'mrkdwn' ,
373+ text : `*Duration:*\n${ formatDuration ( payload . data . totalDurationMs , { precision : 1 } ) ?? '-' } ` ,
374+ } ,
377375 { type : 'mrkdwn' , text : `*Cost:*\n${ formatCost ( payload . data . cost ) } ` } ,
378376 ] ,
379377 } ,
0 commit comments