🔧 Tweaking the file copy end detector method
This commit is contained in:
@@ -140,16 +140,14 @@ export default class ApiService extends Service {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const fileCopyDelaySeconds = 30;
|
const fileCopyDelaySeconds = 3;
|
||||||
const checkFileCopyComplete = (path, previousPath) => {
|
const checkEnd = (path, prev) => {
|
||||||
fs.stat(path, async (err, stat) => {
|
fs.stat(path, async (err, stat) => {
|
||||||
if (err) {
|
// Replace error checking with something appropriate for your app.
|
||||||
throw err;
|
if (err) throw err;
|
||||||
}
|
if (stat.mtime.getTime() === prev.mtime.getTime()) {
|
||||||
if (
|
console.log("finished");
|
||||||
stat.mtime.getTime() ===
|
// Move on: call whatever needs to be called to process the file.
|
||||||
previousPath.mtime.getTime()
|
|
||||||
) {
|
|
||||||
console.log(
|
console.log(
|
||||||
"File detected, starting import..."
|
"File detected, starting import..."
|
||||||
);
|
);
|
||||||
@@ -161,21 +159,21 @@ export default class ApiService extends Service {
|
|||||||
"importqueue.processImport",
|
"importqueue.processImport",
|
||||||
{
|
{
|
||||||
fileObject: {
|
fileObject: {
|
||||||
filePath: walkedFolder[0].filePath,
|
filePath: path,
|
||||||
fileSize: walkedFolder[0].fileSize,
|
fileSize: walkedFolder[0].fileSize,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else
|
||||||
setTimeout(
|
setTimeout(
|
||||||
checkFileCopyComplete,
|
checkEnd,
|
||||||
fileCopyDelaySeconds * 1000,
|
fileCopyDelaySeconds,
|
||||||
path,
|
path,
|
||||||
stat
|
stat
|
||||||
);
|
);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
fileWatcher
|
fileWatcher
|
||||||
.once("add", (path, stats) => {
|
.once("add", (path, stats) => {
|
||||||
console.log("Watcher detected new files.");
|
console.log("Watcher detected new files.");
|
||||||
@@ -187,29 +185,17 @@ export default class ApiService extends Service {
|
|||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log("File copy started...");
|
console.log("File", path, "has been added");
|
||||||
fs.stat(path, (err, stat) => {
|
|
||||||
if (err) {
|
fs.stat(path, function (err, stat) {
|
||||||
console.log(
|
// Replace error checking with something appropriate for your app.
|
||||||
"Error watching file for copy completion. ERR: " +
|
if (err) throw err;
|
||||||
err.message
|
|
||||||
);
|
|
||||||
console.log(
|
|
||||||
"Error file not processed. PATH: " +
|
|
||||||
path
|
|
||||||
);
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
setTimeout(
|
setTimeout(
|
||||||
checkFileCopyComplete,
|
checkEnd,
|
||||||
fileCopyDelaySeconds * 1000,
|
fileCopyDelaySeconds,
|
||||||
path,
|
path,
|
||||||
stat
|
stat
|
||||||
);
|
);
|
||||||
client.emit("action", {
|
|
||||||
type: "LS_COMIC_ADDED",
|
|
||||||
result: path,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
// .once(
|
// .once(
|
||||||
|
|||||||
@@ -75,13 +75,10 @@ export default class QueueService extends Service {
|
|||||||
const result = await extractFromArchive(
|
const result = await extractFromArchive(
|
||||||
job.data.fileObject.filePath
|
job.data.fileObject.filePath
|
||||||
);
|
);
|
||||||
Object.assign(result, {
|
|
||||||
fileSize: job.data.fileObject.fileSize,
|
|
||||||
});
|
|
||||||
const {
|
const {
|
||||||
name,
|
name,
|
||||||
filePath,
|
filePath,
|
||||||
fileSize,
|
|
||||||
extension,
|
extension,
|
||||||
cover,
|
cover,
|
||||||
containedIn,
|
containedIn,
|
||||||
@@ -113,7 +110,7 @@ export default class QueueService extends Service {
|
|||||||
rawFileDetails: {
|
rawFileDetails: {
|
||||||
name,
|
name,
|
||||||
filePath,
|
filePath,
|
||||||
fileSize,
|
fileSize: job.data.fileObject.fileSize,
|
||||||
extension,
|
extension,
|
||||||
containedIn,
|
containedIn,
|
||||||
cover,
|
cover,
|
||||||
@@ -218,17 +215,6 @@ export default class QueueService extends Service {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
await this.getQueue("process.import").on(
|
|
||||||
"drained",
|
|
||||||
async (data) => {
|
|
||||||
client.emit("action", {
|
|
||||||
type: "LS_QUEUE_DRAINED",
|
|
||||||
result: data,
|
|
||||||
});
|
|
||||||
console.log("Drained", data);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user