firebase-cron icon indicating copy to clipboard operation
firebase-cron copied to clipboard

How to know whether the cron is running or not? & How to stop the cron?

Open deepakrnan opened this issue 8 years ago • 7 comments

How to get the cron status? I added the job and its running fine. But i don't know how to stop the cron.

var cron = require("firebase-cron")
var firebase = require('firebase');
firebase.initializeApp(config);
  
var ref = firebase.database().ref();
var queueRef = firebase.database().ref('queue');
var options = {endpoint: 'jobs'};
var cron = new cron(ref, queueRef, options);
cron.addJob('test',` '0 10 11 11 4 *', {foo: 'bar'}, function(err) {
 if (err) return console.error(err);
  console.log('job added');
  console.log();
  })
  cron.getJobs(function(err,jobs){
console.log("err",err)
console.log("all",jobs);
 })
  // cron.run(function(err,job){
  // })

////// some thing like that to stop.
  cron.stop(function(err,job){
  })`

///// some thing like that to get the cron status
  cron.status(function(status){
 // running or not running
  })

deepakrnan avatar May 11 '17 11:05 deepakrnan

You can get a job by name with .getJob. This will have the nextRun timestamp:

cron.getJob('test', function(err, job) {
  if(err) return console.error(err);
  console.log(new Date(job.nextRun));
});

You can remove a job by name with .deleteJob:

cron.deleteJob('test', function(err) {
  if (err) return console.error(err);
  console.log('test deleted');
});

doowb avatar May 11 '17 16:05 doowb

Thank you for the response.

I what to know the status of the cron whether it's running or not.(e.g. active state or inactive state or unknown state.)

And also how to stop the cron. (e.g., To run cron.run but to stop any thing like that)

deepakrnan avatar May 12 '17 04:05 deepakrnan

Ah... for knowing if a job is currently running, then you'd have to look at the firebase-queue stats (this isn't something built into firebase-cron.

cron.run returns a function that will let you stop the timer (this isn't documented right now, but something I'd like to get documented).

var stop = cron.run();
stop();

doowb avatar May 12 '17 05:05 doowb

Thank you.. But how to know the status by watching the firebase-queue, sorry i didn't clear about this point. could you explain me some more...

var stop = cron.run(); stop();

Its not stoping the cron which is in run. Could you please explain me how to stop.

deepakrnan avatar May 12 '17 06:05 deepakrnan

But how to know the status by watching the firebase-queue,

See the firebase-queue documentation. It's something that you'll have to add to your code. firebase-cron only takes data and puts it into the queue at the specified time.

Its not stoping the cron which is in run

Please provide a repository (or runnable code) showing what's happening (remember, don't put real firebase credentials in the repository).

I'm not understanding if you want to stop the cron timer for checking for jobs to run or if you want to stop a job that's currently running.

doowb avatar May 12 '17 21:05 doowb

var stop = cron.run();
stop()

Cron stop working fine. Thank you so much....

But is there any way to get the status of the cron.

Example: case 1:

var stop = cron.run();
stop()

cron.status() // should return 'stopped'

case 2:

var stop = cron.run();
cron.status() // should return 'running'

similar to like that. Please i didn't get any status in the firebase-queue. Please tell me, is there any possibility to get it.

deepakrnan avatar May 17 '17 05:05 deepakrnan

Hi... Anything to get the status.. Please help me....

deepakrnan avatar May 20 '17 09:05 deepakrnan