fix(studio): recover uncertain imports with persistent request identities
This commit is contained in:
1 parent
afea80708c
commit
c977fe95ba
12 files changed
+365
-31
No files matched your search
@@ -10,6 +10,11 @@ export const validJobId = (value: unknown): value is string =>
|
||||
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(
|
||||
value,
|
||||
);
|
||||
export class ImportRequestConflict extends Error {
|
||||
constructor() {
|
||||
super("Request ID already used");
|
||||
}
|
||||
}
|
||||
export class ImportJobStore {
|
||||
constructor(readonly root = importRoot()) {}
|
||||
async save(job: ImportJob) {
|
||||
@@ -31,8 +36,11 @@ export class ImportJobStore {
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
||||
const existing = await this.read(job.id);
|
||||
if (existing.userId !== job.userId)
|
||||
throw Error("Request ID already used");
|
||||
if (
|
||||
existing.userId !== job.userId ||
|
||||
existing.requestFingerprint !== job.requestFingerprint
|
||||
)
|
||||
throw new ImportRequestConflict();
|
||||
return existing;
|
||||
} finally {
|
||||
await fs.unlink(tmp);
|
||||
@@ -106,6 +114,7 @@ export class ImportJobStore {
|
||||
...original,
|
||||
id: retryId,
|
||||
retryOf: id,
|
||||
requestFingerprint: undefined,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
state: "queued",
|
||||
|
||||
Reference in new issue
Block a user