Scheduled job a bit more dynamic
This commit is contained in:
@@ -11,6 +11,9 @@ mongoose.connect("mongodb://localhost:27017/vinlottis", {
|
|||||||
|
|
||||||
const config = require(path.join(__dirname + "/../config/env/push.config"));
|
const config = require(path.join(__dirname + "/../config/env/push.config"));
|
||||||
const Subscription = require(path.join(__dirname + "/../schemas/Subscription"));
|
const Subscription = require(path.join(__dirname + "/../schemas/Subscription"));
|
||||||
|
const lotteryConfig = require(path.join(
|
||||||
|
__dirname + "/../config/env/lottery.config"
|
||||||
|
));
|
||||||
|
|
||||||
const vapidKeys = {
|
const vapidKeys = {
|
||||||
publicKey: config.publicKey,
|
publicKey: config.publicKey,
|
||||||
@@ -52,13 +55,16 @@ const saveToDatabase = async subscription => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
schedule.scheduleJob("0 50 14 * * 5", async () => {
|
schedule.scheduleJob(
|
||||||
let subs = await Subscription.find();
|
`0 50 ${lotteryConfig.hours - 1} * * ${lotteryConfig.date}`,
|
||||||
for (let i = 0; i < subs.length; i++) {
|
async () => {
|
||||||
let subscription = subs[i]; //get subscription from your databse here.
|
let subs = await Subscription.find();
|
||||||
const message = "Husk vinlotteriet, det begynner om 10 minutter!";
|
for (let i = 0; i < subs.length; i++) {
|
||||||
sendNotification(subscription, message);
|
let subscription = subs[i]; //get subscription from your databse here.
|
||||||
|
const message = "Husk vinlotteriet, det begynner om 10 minutter!";
|
||||||
|
sendNotification(subscription, message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
Reference in New Issue
Block a user