Switched from setTimeout to crontab for watch-mode.
This commit is contained in:
parent
23f9ac660a
commit
5b023adf30
|
@ -46,8 +46,7 @@ module.exports = {
|
||||||
avoidDuplicates: true,
|
avoidDuplicates: true,
|
||||||
retries: 3,
|
retries: 3,
|
||||||
watch: {
|
watch: {
|
||||||
interval: 30,
|
schedule: '*/30 * * * *',
|
||||||
ignoreErrors: true,
|
|
||||||
},
|
},
|
||||||
archives: {
|
archives: {
|
||||||
search: false,
|
search: false,
|
||||||
|
|
|
@ -1523,6 +1523,11 @@
|
||||||
"integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=",
|
"integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node-cron": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-cron/-/node-cron-1.2.1.tgz",
|
||||||
|
"integrity": "sha1-jJC8XccjpWKJsHhmVatKHEy2A2g="
|
||||||
|
},
|
||||||
"node-exiftool": {
|
"node-exiftool": {
|
||||||
"version": "2.3.0",
|
"version": "2.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/node-exiftool/-/node-exiftool-2.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/node-exiftool/-/node-exiftool-2.3.0.tgz",
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
"fs-extra": "^5.0.0",
|
"fs-extra": "^5.0.0",
|
||||||
"js-yaml": "^3.12.0",
|
"js-yaml": "^3.12.0",
|
||||||
"mime-types": "^2.1.18",
|
"mime-types": "^2.1.18",
|
||||||
|
"node-cron": "^1.2.1",
|
||||||
"node-exiftool": "^2.3.0",
|
"node-exiftool": "^2.3.0",
|
||||||
"node-fetch": "^2.1.2",
|
"node-fetch": "^2.1.2",
|
||||||
"object.omit": "^3.0.0",
|
"object.omit": "^3.0.0",
|
||||||
|
|
17
src/app.js
17
src/app.js
|
@ -4,6 +4,7 @@ const config = require('config');
|
||||||
const Snoowrap = require('snoowrap');
|
const Snoowrap = require('snoowrap');
|
||||||
const exiftool = require('node-exiftool');
|
const exiftool = require('node-exiftool');
|
||||||
const exiftoolBin = require('dist-exiftool');
|
const exiftoolBin = require('dist-exiftool');
|
||||||
|
const cron = require('node-cron');
|
||||||
const { format } = require('date-fns');
|
const { format } = require('date-fns');
|
||||||
|
|
||||||
require('array.prototype.flatten').shim();
|
require('array.prototype.flatten').shim();
|
||||||
|
@ -40,12 +41,6 @@ function fetchSavePosts(userPosts, ep) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initApp() {
|
async function initApp() {
|
||||||
function watch() {
|
|
||||||
console.log(`[${format(new Date(), 'YYYY-MM-DD HH:mm:ss')}] Watch-mode enabled, checking for new posts ${config.fetch.watch.interval} minutes from now.`);
|
|
||||||
|
|
||||||
setTimeout(initApp, Math.ceil(config.fetch.watch.interval) * 1000 * 60);
|
|
||||||
}
|
|
||||||
|
|
||||||
const usersProvided = args.users && args.users.length;
|
const usersProvided = args.users && args.users.length;
|
||||||
const postIdsProvided = args.posts && args.posts.length;
|
const postIdsProvided = args.posts && args.posts.length;
|
||||||
|
|
||||||
|
@ -62,17 +57,17 @@ async function initApp() {
|
||||||
await ep.close();
|
await ep.close();
|
||||||
|
|
||||||
if (args.watch) {
|
if (args.watch) {
|
||||||
watch();
|
console.log(`[${format(new Date(), 'YYYY-MM-DD HH:mm:ss')}] Watch-mode enabled, checking again for new posts according to crontab '${config.fetch.watch.schedule}'.`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
||||||
if (args.watch && config.fetch.watch.ignoreErrors) {
|
|
||||||
watch();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
initApp();
|
initApp();
|
||||||
|
|
||||||
|
if (args.watch) {
|
||||||
|
cron.schedule(config.fetch.watch.schedule, initApp);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue