Fix: task pool cannot release task after it fails

This commit is contained in:
HFO4 2022-02-27 14:35:47 +08:00
parent c7ad37a2c6
commit a8627595f3
3 changed files with 12 additions and 5 deletions

View File

@ -4,7 +4,7 @@ import { Status } from "./core/uploader/base";
export function useUpload(uploader) {
const startTimeRef = useRef(null);
const [status, setStatus] = useState(uploader.status);
const [error, setError] = useState(null);
const [error, setError] = useState(uploader.error);
useEffect(() => {
startTimeRef.current = Date.now();
/* eslint-disable @typescript-eslint/no-empty-function */

View File

@ -72,11 +72,11 @@ export default abstract class Base {
return;
}
this.logger.info("Enqueued in manager pool");
this.manager.pool.enqueue(this).catch((e) => {
this.logger.info("Upload task failed with error:", e);
this.setError(e);
});
this.logger.info("Enqueued in manager pool");
};
public upload = async () => {

View File

@ -23,16 +23,23 @@ export class Pool {
});
}
release(item: QueueContent) {
this.processing = this.processing.filter((v) => v !== item);
this.check();
}
run(item: QueueContent) {
this.queue = this.queue.filter((v) => v !== item);
this.processing.push(item);
item.uploader.upload().then(
() => {
this.processing = this.processing.filter((v) => v !== item);
item.resolve();
this.check();
this.release(item);
},
(err) => item.reject(err)
(err) => {
item.reject(err);
this.release(item);
}
);
}