How to use agenda - 5 common examples

To help you get started, we’ve selected a few agenda examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github agenda / agenda / examples / concurrency.js View on Github external
/**
 * @file Illustrate concurrency and locking
 */
import Agenda from 'agenda';

function time() {
  return new Date().toTimeString().split(' ')[0];
}

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

const agenda = new Agenda({
  db: {
    address: 'mongodb://agendan:nuam0agenda@ds052408.mlab.com:52408/agenda',
    options: { useNewUrlParser: true },
    collection: `agendaJobs-${Math.random()}`,  // start fresh every time
  },
});

let jobRunCount = 1;
agenda.define('long-running job', {
  lockLifetime: 5 * 1000,  // max amount of time the job should take
  concurrency: 3,  // max number of job instances to run at the same time
}, async (job, done) => {
  const thisJob = jobRunCount++;
  console.log(`#${thisJob} started`);

  // 3 job instances will be running at the same time, as specified by `concurrency` above
github oors / oors / packages / oors-scheduler / src / index.js View on Github external
async setup({ isWorker }) {
    await this.loadDependencies(['oors.mongodb', 'oors.logger', 'oors.autoloader']);

    this.agenda = new Agenda({
      mongo: this.deps['oors.mongodb'].getConnectionDb(),
      ...this.getConfig('agendaConfig'),
    });

    this.export({
      agenda: this.agenda,
      defineJob: this.defineJob,
      defineJobs: this.defineJobs,
      createJob: this.createJob,
    });

    await this.runHook('loadJobs', this.collectFromModule, {
      agenda: this.agenda,
      defineJob: this.defineJob,
      defineJobs: this.defineJobs,
    });
github jembi / openhim-core-js / src / server.js View on Github external
function startAgenda () {
    const deferred = defer()
    agenda = new Agenda({
      mongo: connectionAgenda
    })

    agenda.on('start', job => logger.info(`starting job: ${job.attrs.name}, Last Ran at: ${job.attrs.lastRunAt}`))

    agenda.on('fail', (err, job) => logger.error(`Job ${job.attrs.name} failed with ${err.message}`))

    agenda.on('complete', job => logger.info(`Job ${job.attrs.name} has completed`))

    agenda.on('ready', () => {
      if (config.alerts.enableAlerts) { alerts.setupAgenda(agenda) }
      if (config.reports.enableReports) { reports.setupAgenda(agenda) }
      if (config.bodyCull.enabled) { bodyCull.setupAgenda(agenda) }
      autoRetry.setupAgenda(agenda)
      if (config.polling.enabled) {
        return polling.setupAgenda(agenda, () =>
github shadowlik / muchas-framework / src / routine / RoutineLoader.ts View on Github external
constructor(options: RoutinesOptions, Apm?: any) {
        let opt = {};
        this.Web = options.web;
        this.apm = Apm;
        if (options.mongoConString) {
            opt = {
                db: {
                    address: options.mongoConString || null,
                    collection: 'agenda',
                    options: {
                        useNewUrlParser: true,
                    }
                }
            }
        }
        this.Agenda = new agenda(opt);
        this.Agenda.name(`${os.hostname}-${process.pid}`);
        this.Agenda.start();

        this.Web.app.use('/routines', Agendash(this.Agenda));
    }
github agenda / agenda-rest / src / index.js View on Github external
import {promisify} from 'util';
import Agenda from 'agenda';
import settings from '../settings';
import {bootstrapKoaApp} from './util';
import {defineJob, jobOperations, jobAssertions, promiseJobOperation} from './job';

const {app, router} = bootstrapKoaApp();

const agenda = new Agenda({
  db: {
    address: settings.agendaMongoUrl,
    collection: settings.collection
  }
});

const jobsReady = agenda._ready
  .then(async () => {
    const jobs = agenda._mdb.collection(settings.definitions);
    jobs.toArray = () => {
      const jobsCursor = jobs.find();
      return promisify(jobsCursor.toArray).bind(jobsCursor)();
    };

    await jobs.toArray()
      .then(jobsArray => Promise.all(jobsArray.map(job => defineJob(job, jobs, agenda))));

agenda

Light weight job scheduler for Node.js

MIT
Latest version published 2 years ago

Package Health Score

65 / 100
Full package analysis

Popular agenda functions