suppose i got date as x=12 y=45 and i want to perform a task at 12:45 daily using agenda node js. So my question is ,
how to pass date from js variable to Agenda.schedule("at x:y",'doSometask')
Asked
Active
Viewed 599 times
2 Answers
0
simple use this.just concatenate the variable in string.
var x=12;
var y=45;
a = "at "+x+":"+y;
Agenda.schedule(a,'doSometask')

Shekhar Tyagi
- 1,644
- 13
- 18
-
Thanx for the answer! What if i got that time value from mongo db and if i change the value from my mongodb collection ! will the task timing change automatically or not ? – Jaini Feb 10 '17 at 06:22
-
yes the time change change automatically if you used the data coming from mongo like the value of x and y coming from mongo. if answer helps you then upvote. – Shekhar Tyagi Feb 10 '17 at 06:26
-
`var Agenda = require('agenda'); var agenda = new Agenda(); agenda.database('192.168.2.152:27017/agenda-test', 'agendaJobs'); var x=11; var y=59; a = "at "+x+":"+y; agenda.define('init', function (job,done) { console.log("INIT AGENDA"); done(); }); agenda.on('ready', function () { console.log("Agenda ready to start"); agenda.schedule(a,'init'); agenda.start(); });` – Jaini Feb 10 '17 at 06:31
-
can you use find or findOne to find the value of x and y from db. you can also refer to this https://github.com/shekhartyagi26/TodoApp/blob/master/routes/index.js – Shekhar Tyagi Feb 10 '17 at 06:38
-
you can also use find value from database like this database_name.findOne({id:req.body.id}, function (err, user) { if (err) { res.json({status: 0, message: err}); } if (!user) { res.json({status: 0, msg: "not found"}); } res.json(user); }) – Shekhar Tyagi Feb 10 '17 at 06:43
0
var x=14;
var y=23;
var z=x-2;
a = "at "+z+":"+y;
agenda.define('init', function (job) {
console.log("INIT AGENDA");
//job.schedule(a);
//job.save();
});
agenda.on('ready', function () {
console.log("Agenda ready to start");
agenda.schedule(a,'init');
agenda.start();
});
This worked for me !!

Jaini
- 90
- 10