mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
Concurrent-Jobs (#7)
Fredy 2.0.0 introduces the concept of search jobs. You can now configure multiple of these jobs running in the same instance of Fredy. Also a new API has been created 🎉
This commit is contained in:
committed by
GitHub
parent
52a32f7453
commit
770d30af95
41
index.js
41
index.js
@@ -1,13 +1,36 @@
|
||||
const fs = require('fs');
|
||||
const path = './lib/provider';
|
||||
const sources = fs.readdirSync(path);
|
||||
const provider = fs.readdirSync(path);
|
||||
const config = require('./conf/config.json');
|
||||
const stats = require('./lib/services/stats');
|
||||
const { setLastJobExecution, init: storeInit } = require('./lib/services/store');
|
||||
const FredyRuntime = require('./lib/FredyRuntime');
|
||||
|
||||
setInterval(
|
||||
(function exec() {
|
||||
sources.forEach(source => require(`${path}/${source}`).run(stats));
|
||||
return exec;
|
||||
})(),
|
||||
config.interval * 60 * 1000
|
||||
);
|
||||
//starting the api service
|
||||
require('./lib/api/api');
|
||||
|
||||
storeInit().then(() => {
|
||||
setInterval(
|
||||
(function exec() {
|
||||
Object.keys(config.jobs).forEach(jobKey => {
|
||||
const jobConfig = config.jobs[jobKey];
|
||||
provider
|
||||
.map(pro => require(`${path}/${pro}`))
|
||||
.forEach(pro => {
|
||||
const providerId = pro.id();
|
||||
if (providerId == null || providerId.length === 0) {
|
||||
throw new Error('Provider id must not be empty. => ' + pro);
|
||||
}
|
||||
const providerConfig = jobConfig.provider[providerId];
|
||||
if (providerConfig == null) {
|
||||
throw new Error(`Provider Config for provider with id ${providerId} not found.`);
|
||||
}
|
||||
pro.init(providerConfig, jobConfig.blacklist, jobConfig.blacklistedDistricts);
|
||||
new FredyRuntime(pro.config, jobConfig.notification, providerId, jobKey).execute();
|
||||
setLastJobExecution(jobKey);
|
||||
});
|
||||
});
|
||||
return exec;
|
||||
})(),
|
||||
config.interval * 60 * 1000
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user