feat: enhance date formatting options to include seconds in logs

This commit is contained in:
Simon Larsen
2025-02-24 18:45:46 +00:00
parent 4dcd691ef7
commit 2ea10bfbdd
4 changed files with 37 additions and 12 deletions

View File

@@ -819,26 +819,37 @@ export default class OneUptimeDate {
return moment(date).isBefore(endDate);
}
public static getCurrentDateAsFormattedString(): string {
return this.getDateAsFormattedString(new Date());
public static getCurrentDateAsFormattedString(options?: {
onlyShowDate?: boolean;
showSeconds?: boolean;
}): string {
return this.getDateAsFormattedString(new Date(), options);
}
public static getDateAsFormattedString(
date: string | Date,
onlyShowDate?: boolean,
options?: {
onlyShowDate?: boolean;
showSeconds?: boolean;
}
): string {
date = this.fromString(date);
let formatstring: string = "MMM DD YYYY, HH:mm";
if (onlyShowDate) {
if(options?.showSeconds){
formatstring = "MMM DD YYYY, HH:mm:ss";
}
if (options?.onlyShowDate) {
formatstring = "MMM DD, YYYY";
}
return (
moment(date).format(formatstring) +
" " +
(onlyShowDate ? "" : this.getCurrentTimezoneString())
(options?.onlyShowDate ? "" : this.getCurrentTimezoneString())
);
}

View File

@@ -36,7 +36,9 @@ RunCron(
workflowStatus: WorkflowStatus.Error,
logs: `${
stalledWorkflowLog.logs
} \n ${OneUptimeDate.getCurrentDateAsFormattedString()}: Workflow was not picked up by the runner and has timed out.`,
} \n ${OneUptimeDate.getCurrentDateAsFormattedString({
showSeconds: true,
})}: Workflow was not picked up by the runner and has timed out.`,
},
props: {
isRoot: true,

View File

@@ -100,7 +100,9 @@ export default class QueueWorkflow {
runLog.projectId = workflow.projectId;
runLog.workflowStatus = WorkflowStatus.WorkflowCountExceeded;
runLog.logs =
OneUptimeDate.getCurrentDateAsFormattedString() +
OneUptimeDate.getCurrentDateAsFormattedString({
showSeconds: true,
}) +
": Workflow cannot run because subscription is unpaid.";
await WorkflowLogService.create({
@@ -135,7 +137,9 @@ export default class QueueWorkflow {
runLog.projectId = workflow.projectId;
runLog.workflowStatus = WorkflowStatus.WorkflowCountExceeded;
runLog.logs =
OneUptimeDate.getCurrentDateAsFormattedString() +
OneUptimeDate.getCurrentDateAsFormattedString({
showSeconds: true,
}) +
`: Workflow cannot run because it already ran ${workflowCount.toNumber()} in the last 30 days. Your current plan limit is ${
WorkflowPlan[projectPlan.plan]
}`;
@@ -160,7 +164,9 @@ export default class QueueWorkflow {
runLog.projectId = workflow.projectId;
runLog.workflowStatus = WorkflowStatus.Scheduled;
runLog.logs =
OneUptimeDate.getCurrentDateAsFormattedString() +
OneUptimeDate.getCurrentDateAsFormattedString({
showSeconds: true,
}) +
`: Workflow ${workflowId.toString()} Scheduled.`;
workflowLog = await WorkflowLogService.create({

View File

@@ -107,7 +107,9 @@ export default class RunWorkflow {
runLog.projectId = workflow.projectId!;
runLog.workflowStatus = WorkflowStatus.Scheduled;
runLog.logs =
OneUptimeDate.getCurrentDateAsFormattedString() +
OneUptimeDate.getCurrentDateAsFormattedString({
showSeconds: true,
}) +
`: Workflow ${runProps.workflowId.toString()} Scheduled.`;
runProps.workflowLogId = (
@@ -485,11 +487,15 @@ export default class RunWorkflow {
if (typeof data === "string") {
this.logs.push(
OneUptimeDate.getCurrentDateAsFormattedString() + ": " + data,
OneUptimeDate.getCurrentDateAsFormattedString({
showSeconds: true,
}) + ": " + data,
);
} else {
this.logs.push(
OneUptimeDate.getCurrentDateAsFormattedString() +
OneUptimeDate.getCurrentDateAsFormattedString({
showSeconds: true,
}) +
": " +
JSON.stringify(data),
);