🧲 Added a job for deleted torrents clean-up
This commit is contained in:
@@ -51,9 +51,10 @@ export default class JobQueueService extends Service {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
enqueue: {
|
enqueue: {
|
||||||
queue: true,
|
queue: true,
|
||||||
rest: "/GET enqueue",
|
rest: "GET /enqueue",
|
||||||
handler: async (
|
handler: async (
|
||||||
ctx: Context<{ queueName: string; description: string }>
|
ctx: Context<{ queueName: string; description: string }>
|
||||||
) => {
|
) => {
|
||||||
@@ -73,6 +74,49 @@ export default class JobQueueService extends Service {
|
|||||||
return job.id;
|
return job.id;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
checkForDeletedTorrents: {
|
||||||
|
queue: true,
|
||||||
|
rest: "GET /checkForDeletedTorrents",
|
||||||
|
handler: async (ctx: Context<{}>) => {
|
||||||
|
const job = await this.localQueue(
|
||||||
|
ctx,
|
||||||
|
"deletedTorrents",
|
||||||
|
"bird",
|
||||||
|
{
|
||||||
|
repeat: {
|
||||||
|
every: 10000, // Repeat every 10000 ms
|
||||||
|
limit: 100, // Limit to 100 repeats
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return job;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
deletedTorrents: {
|
||||||
|
rest: "GET /deletedTorrents",
|
||||||
|
handler: async (
|
||||||
|
ctx: Context<{
|
||||||
|
birdName: String;
|
||||||
|
}>
|
||||||
|
) => {
|
||||||
|
console.info(
|
||||||
|
`Scheduled job for deleting torrents from mongo fired.`
|
||||||
|
);
|
||||||
|
// 1. query mongo for infohashes
|
||||||
|
const infoHashes = await this.broker.call(
|
||||||
|
"library.getInfoHashes",
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
// 2. query qbittorrent to see if they exist
|
||||||
|
const torrents: any = await this.broker.call(
|
||||||
|
"qbittorrent.getTorrentRealTimeStats",
|
||||||
|
{ infoHashes }
|
||||||
|
);
|
||||||
|
console.log("sudarshan", torrents);
|
||||||
|
// 3. If they do, don't do anything
|
||||||
|
// 4. If they don't purge them from mongo
|
||||||
|
},
|
||||||
|
},
|
||||||
// Comic Book Import Job Queue
|
// Comic Book Import Job Queue
|
||||||
"enqueue.async": {
|
"enqueue.async": {
|
||||||
handler: async (
|
handler: async (
|
||||||
@@ -437,6 +481,7 @@ export default class JobQueueService extends Service {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
methods: {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -444,20 +444,45 @@ export default class ImportService extends Service {
|
|||||||
infoHash,
|
infoHash,
|
||||||
} = ctx.params;
|
} = ctx.params;
|
||||||
console.log(JSON.stringify(ctx.params, null, 4));
|
console.log(JSON.stringify(ctx.params, null, 4));
|
||||||
|
try {
|
||||||
return await Comic.findByIdAndUpdate(
|
return await Comic.findByIdAndUpdate(
|
||||||
new ObjectId(comicObjectId),
|
new ObjectId(comicObjectId),
|
||||||
{
|
{
|
||||||
$push: {
|
$push: {
|
||||||
"acquisition.torrent": {
|
"acquisition.torrent": {
|
||||||
infoHash,
|
infoHash,
|
||||||
name,
|
name,
|
||||||
announce,
|
announce,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
{ new: true, safe: true, upsert: true }
|
||||||
{ new: true, safe: true, upsert: true }
|
);
|
||||||
);
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
getInfoHashes: {
|
||||||
|
rest: "GET /getInfoHashes",
|
||||||
|
handler: async (ctx: Context<{}>) => {
|
||||||
|
try {
|
||||||
|
return await Comic.aggregate([
|
||||||
|
{
|
||||||
|
$unwind: "$acquisition.torrent",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$group: {
|
||||||
|
_id: "$_id",
|
||||||
|
infoHashes: {
|
||||||
|
$push: "$acquisition.torrent.infoHash",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
} catch (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getComicBooks: {
|
getComicBooks: {
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ export default class SettingsService extends Service {
|
|||||||
// Find the settings with the dynamic projection
|
// Find the settings with the dynamic projection
|
||||||
const settings = await Settings.find({}, projection);
|
const settings = await Settings.find({}, projection);
|
||||||
|
|
||||||
// Check if settings are empty
|
|
||||||
if (settings.length === 0) {
|
if (settings.length === 0) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user