mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[scraper] adds scheduling flag to enable it
This commit is contained in:
@@ -26,17 +26,27 @@ async function scrape() {
|
|||||||
return PROVIDERS
|
return PROVIDERS
|
||||||
.reduce(async (previousPromise, nextProvider) => {
|
.reduce(async (previousPromise, nextProvider) => {
|
||||||
await previousPromise;
|
await previousPromise;
|
||||||
return nextProvider.scrape().catch(() => Promise.resolve());
|
return nextProvider.scrape().catch(error => {
|
||||||
|
console.warn(`Failed ${nextProvider.NAME} scraping due: `, error);
|
||||||
|
return Promise.resolve()
|
||||||
|
});
|
||||||
}, Promise.resolve());
|
}, Promise.resolve());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function enableScheduling() {
|
||||||
|
if (process.env.ENABLE_SCHEDULING) {
|
||||||
|
schedule.scheduleJob(SCRAPE_CRON, () => scrape());
|
||||||
|
} else {
|
||||||
|
scrape();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
server.get('/', function (req, res) {
|
server.get('/', function (req, res) {
|
||||||
res.send(200);
|
res.send(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(process.env.PORT || 7000, async function () {
|
server.listen(process.env.PORT || 7000, async function () {
|
||||||
await connect();
|
await connect();
|
||||||
// schedule.scheduleJob(SCRAPE_CRON, () => scrape());
|
|
||||||
console.log('Scraper started');
|
console.log('Scraper started');
|
||||||
scrape();
|
enableScheduling();
|
||||||
});
|
});
|
||||||
@@ -86,4 +86,4 @@ function typeMapping() {
|
|||||||
return mapping;
|
return mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { scrape };
|
module.exports = { scrape, NAME };
|
||||||
@@ -193,4 +193,4 @@ async function checkIfExists(torrent) {
|
|||||||
return { ...torrent, size: existingTorrent.size, seeders: existingTorrent.seeders };
|
return { ...torrent, size: existingTorrent.size, seeders: existingTorrent.seeders };
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { scrape };
|
module.exports = { scrape, NAME };
|
||||||
@@ -95,4 +95,4 @@ async function findTorrent(record) {
|
|||||||
return Promise.reject("not found");
|
return Promise.reject("not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { scrape };
|
module.exports = { scrape, NAME };
|
||||||
@@ -84,4 +84,4 @@ function typeMapping() {
|
|||||||
return mapping;
|
return mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { scrape };
|
module.exports = { scrape, NAME };
|
||||||
@@ -73,4 +73,4 @@ function getType(category) {
|
|||||||
return Type.MOVIE;
|
return Type.MOVIE;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { scrape };
|
module.exports = { scrape, NAME };
|
||||||
@@ -100,4 +100,4 @@ function getType(category) {
|
|||||||
return Type.MOVIE;
|
return Type.MOVIE;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { scrape };
|
module.exports = { scrape, NAME };
|
||||||
@@ -178,4 +178,4 @@ function downloadDump(dump) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { scrape };
|
module.exports = { scrape, NAME };
|
||||||
@@ -82,4 +82,4 @@ async function processTorrentRecord(record) {
|
|||||||
return createTorrentEntry(torrent);
|
return createTorrentEntry(torrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { scrape };
|
module.exports = { scrape, NAME };
|
||||||
@@ -109,4 +109,4 @@ async function processTorrentRecord(record) {
|
|||||||
return createTorrentEntry(torrent);
|
return createTorrentEntry(torrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { scrape };
|
module.exports = { scrape, NAME };
|
||||||
Reference in New Issue
Block a user