Skip to content

Commit 1a8ab84

Browse files
committed
fix inflight upload jobs persisted status incorrect
1 parent a0f2d3e commit 1a8ab84

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

src/main/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ ipcMain.on("UploaderManager", (event, message) => {
260260
});
261261

262262
uploaderProcess.on("message", (message) => {
263-
event.sender.send("UploaderManager-reply", message);
263+
if (win && !win.isDestroyed()) {
264+
event.sender.send("UploaderManager-reply", message);
265+
}
264266
switch (message.action) {
265267
case UploadAction.UpdateUiData: {
266268
uploadRunning = message.data.running;
@@ -666,7 +668,11 @@ app.on("window-all-closed", () => {
666668
// On OS X it is common for applications and their menu bar
667669
// to stay active until the user quits explicitly with Cmd + Q
668670
//if (process.platform !== 'darwin') {
669-
app.quit();
671+
672+
// resolve inflight jobs persisted status not correct
673+
setTimeout(() => {
674+
app.quit();
675+
}, 3000);
670676
//}
671677
});
672678

src/main/uploader/index.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,44 @@ process.on("message", (message: UploadMessage) => {
111111
}
112112
});
113113

114+
let isCleanup = false;
115+
function handleExit() {
116+
if (isCleanup) {
117+
return Promise.resolve();
118+
}
119+
120+
isCleanup = true;
121+
122+
uploadManager.stopAllJobs({
123+
matchStatus: [Status.Waiting],
124+
});
125+
126+
return new Promise<void>((resolve, reject) => {
127+
try {
128+
// resolve inflight jobs persisted status not correct
129+
setTimeout(() => {
130+
uploadManager.stopAllJobs({
131+
matchStatus: [Status.Running],
132+
});
133+
uploadManager.persistJobs(true);
134+
resolve();
135+
}, 2000);
136+
} catch {
137+
reject()
138+
}
139+
});
140+
}
141+
142+
114143
process.on("exit", () => {
115-
uploadManager.persistJobs(true);
144+
handleExit()
145+
});
146+
147+
process.on('SIGTERM', () => {
148+
handleExit()
149+
.then(() => {
150+
process.exit(0);
151+
});
116152
});
117153

118154
function handleJobDone(jobId: string, job?: UploadJob) {

src/main/uploader/upload-manager.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ export default class UploadManager {
425425
},
426426
);
427427

428-
if (job.status === Status.Running) {
428+
if ([Status.Waiting, Status.Running].includes(job.status)) {
429429
job.stop();
430430
}
431431

@@ -481,11 +481,20 @@ export default class UploadManager {
481481
this.scheduleJobs();
482482
}
483483

484-
public stopAllJobs(): void {
484+
public stopAllJobs({
485+
matchStatus,
486+
}: {
487+
matchStatus: Status[],
488+
} = {
489+
matchStatus: [],
490+
}): void {
485491
this.jobIds
486492
.map(id => this.jobs.get(id))
487493
.forEach(job => {
488-
if (!job) {
494+
if (!job || ![Status.Running, Status.Waiting].includes(job.status)) {
495+
return;
496+
}
497+
if (!matchStatus.includes(job.status)){
489498
return;
490499
}
491500
job.stop();

0 commit comments

Comments
 (0)