Skip to content

use async-queue #333

@ORESoftware

Description

@ORESoftware

Right now I have this:

'use strict';

//dts
import {CDTChronJobItem} from "../../index";

//core
import cp = require('child_process');
import path = require('path');
import fs = require('fs');

// npm
const {CronJob} = require('cron');

/////////////////////////////////////////////////////////////////////////

export const run = function (v: CDTChronJobItem, projectRoot: string) {
  
  const id = v.id;
  const schedule = v.schedule;
  
  const onStart = function () {
    
    console.log(`job with id="${id}" has started.`);
    
    const shp = path.resolve(projectRoot + '/lib/shell-scripts/mongo-restore.sh');
    const k = cp.spawn('bash');
    
    k.stdin.write(fs.createReadStream(shp));
    
    k.once('exit', function () {
      k.unref();
    });
  
  };
  
  const onStop = function () {
    console.log(`job with id="${id}" has stopped.`);
  };
  
  
  return new CronJob(
    schedule,
    onStart,
    onStop,
    false, // don't start the job just yet
    'America/Los_Angeles'
  );
  
};

it would be interesting if the chron job could only start once the previous one had completed.

the right way to do that, would be to use something like async-queue, and my onStart function would have to take a callback.

Is it possible to do that with node-chron? Just curious.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions