Fix time and storage when workflow is running
Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
44
src/act.ts
44
src/act.ts
@@ -54,8 +54,10 @@ export interface History {
|
|||||||
index: number,
|
index: number,
|
||||||
name: string,
|
name: string,
|
||||||
status: HistoryStatus,
|
status: HistoryStatus,
|
||||||
start?: string,
|
date?: {
|
||||||
end?: string,
|
start: string,
|
||||||
|
end: string,
|
||||||
|
}
|
||||||
output?: string,
|
output?: string,
|
||||||
taskExecution?: TaskExecution,
|
taskExecution?: TaskExecution,
|
||||||
commandArgs: CommandArgs
|
commandArgs: CommandArgs
|
||||||
@@ -90,7 +92,18 @@ export class Act {
|
|||||||
this.workflowsManager = new WorkflowsManager();
|
this.workflowsManager = new WorkflowsManager();
|
||||||
this.settingsManager = new SettingsManager();
|
this.settingsManager = new SettingsManager();
|
||||||
this.storageManager = new StorageManager(context);
|
this.storageManager = new StorageManager(context);
|
||||||
this.workspaceHistory = this.storageManager.get<{ [path: string]: History[] }>(StorageKey.WorkspaceHistory) || {};
|
|
||||||
|
const workspaceHistory = this.storageManager.get<{ [path: string]: History[] }>(StorageKey.WorkspaceHistory) || {};
|
||||||
|
for (const [path, historyLogs] of Object.entries(workspaceHistory)) {
|
||||||
|
workspaceHistory[path] = historyLogs.map(history => {
|
||||||
|
if (history.status === HistoryStatus.Running) {
|
||||||
|
history.status = HistoryStatus.Cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
return history;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.workspaceHistory = workspaceHistory;
|
||||||
|
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case 'win32':
|
case 'win32':
|
||||||
@@ -197,7 +210,6 @@ export class Act {
|
|||||||
index: historyIndex,
|
index: historyIndex,
|
||||||
name: `${commandArgs.name} #${this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath].length + 1}`,
|
name: `${commandArgs.name} #${this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath].length + 1}`,
|
||||||
status: HistoryStatus.Running,
|
status: HistoryStatus.Running,
|
||||||
start: new Date().toISOString(),
|
|
||||||
commandArgs: commandArgs
|
commandArgs: commandArgs
|
||||||
});
|
});
|
||||||
historyTreeDataProvider.refresh();
|
historyTreeDataProvider.refresh();
|
||||||
@@ -236,18 +248,25 @@ export class Act {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const exec = child_process.spawn(command, { cwd: commandArgs.workspaceFolder.uri.fsPath, shell: env.shell });
|
const exec = child_process.spawn(command, { cwd: commandArgs.workspaceFolder.uri.fsPath, shell: env.shell });
|
||||||
|
const setDate = (actDate?: string) => {
|
||||||
|
const date = actDate ? new Date(actDate).toString() : new Date().toString();
|
||||||
|
|
||||||
|
if (!this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].date) {
|
||||||
|
this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].date = {
|
||||||
|
start: date,
|
||||||
|
end: date,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].date!.end = date;
|
||||||
|
}
|
||||||
|
}
|
||||||
const handleIO = (data: any) => {
|
const handleIO = (data: any) => {
|
||||||
const lines: string[] = data.toString().split('\n').filter((line: string) => line != '');
|
const lines: string[] = data.toString().split('\n').filter((line: string) => line != '');
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
const jsonLine = JSON.parse(line);
|
const jsonLine = JSON.parse(line);
|
||||||
|
setDate(jsonLine.time);
|
||||||
if (!this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].start) {
|
|
||||||
this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].start = jsonLine.time;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (jsonLine.jobResult) {
|
if (jsonLine.jobResult) {
|
||||||
this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].end = jsonLine.time;
|
|
||||||
|
|
||||||
switch (jsonLine.jobResult) {
|
switch (jsonLine.jobResult) {
|
||||||
case 'success':
|
case 'success':
|
||||||
this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].status = HistoryStatus.Success;
|
this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].status = HistoryStatus.Success;
|
||||||
@@ -266,9 +285,7 @@ export class Act {
|
|||||||
exec.stdout.on('data', handleIO);
|
exec.stdout.on('data', handleIO);
|
||||||
exec.stderr.on('data', handleIO);
|
exec.stderr.on('data', handleIO);
|
||||||
exec.on('close', (code) => {
|
exec.on('close', (code) => {
|
||||||
if (!this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].end) {
|
setDate();
|
||||||
this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].end = new Date().toISOString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].status === HistoryStatus.Running) {
|
if (this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].status === HistoryStatus.Running) {
|
||||||
this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].status = HistoryStatus.Failed;
|
this.workspaceHistory[commandArgs.workspaceFolder.uri.fsPath][historyIndex].status = HistoryStatus.Failed;
|
||||||
@@ -291,7 +308,6 @@ export class Act {
|
|||||||
writeEmitter.fire(`Environments: OSSBUILD\r\n`);
|
writeEmitter.fire(`Environments: OSSBUILD\r\n`);
|
||||||
writeEmitter.fire(`Variables: VARIABLE1=ABC, VARIABLE2=DEF\r\n`);
|
writeEmitter.fire(`Variables: VARIABLE1=ABC, VARIABLE2=DEF\r\n`);
|
||||||
writeEmitter.fire(`Secrets: SECRET1=ABC, SECRET2=DEF\r\n`);
|
writeEmitter.fire(`Secrets: SECRET1=ABC, SECRET2=DEF\r\n`);
|
||||||
writeEmitter.fire(`Timestamp: ${new Date().toLocaleTimeString()}\r\n`);
|
|
||||||
writeEmitter.fire(`Command: ${command}\r\n`);
|
writeEmitter.fire(`Command: ${command}\r\n`);
|
||||||
writeEmitter.fire(`\r\n`);
|
writeEmitter.fire(`\r\n`);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi
|
|||||||
this.history = history;
|
this.history = history;
|
||||||
|
|
||||||
let totalDuration: string | undefined;
|
let totalDuration: string | undefined;
|
||||||
if (history.start) {
|
if (history.date) {
|
||||||
const start = new Date(history.start).getTime();
|
const start = new Date(history.date.start).getTime();
|
||||||
const end = history.end ? new Date(history.end).getTime() : new Date().getTime();
|
const end = new Date(history.date.end).getTime();
|
||||||
totalDuration = `${((end - start) / 1000).toFixed(0).toString()}s`;
|
totalDuration = `${((end - start) / 1000).toFixed(0).toString()}s`;
|
||||||
this.description = totalDuration;
|
this.description = totalDuration;
|
||||||
}
|
}
|
||||||
@@ -35,8 +35,8 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi
|
|||||||
}
|
}
|
||||||
this.tooltip = `Name: ${history.name}\n` +
|
this.tooltip = `Name: ${history.name}\n` +
|
||||||
`Status: ${history.status}\n` +
|
`Status: ${history.status}\n` +
|
||||||
`Started: ${history.start ? history.start : 'N/A'}\n` +
|
`Started: ${history.date ? history.date.start : 'N/A'}\n` +
|
||||||
`Ended: ${history.end ? history.end : 'N/A'}\n` +
|
`Ended: ${history.date ? history.date.end : 'N/A'}\n` +
|
||||||
(totalDuration ? `Total Duration: ${totalDuration}\n` : ``);
|
(totalDuration ? `Total Duration: ${totalDuration}\n` : ``);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user