mirror of
https://github.com/cloudreve/frontend.git
synced 2025-12-26 04:02:47 +00:00
Fix: task pool cannot release task after it fails
This commit is contained in:
parent
c7ad37a2c6
commit
a8627595f3
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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 () => {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue