Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with external trigger #1581

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

giuseppecastaldo
Copy link

Summary of Changes

This pull request removes the instantiation of JobProcessor within the Agenda constructor. This change enables calling the process() function externally, allowing integration with external triggers such as REST API calls, suitable for serverless functions.

Changes Made

  • Removed the instantiation of setInterval() from the JobProcessor constructor.

Usage example

const mongoConnectionString = 'mongodb://127.0.0.1/agenda';

const agenda = new Agenda({ db: { address: mongoConnectionString } });

agenda.define('delete old users', async job => {
	await User.remove({ lastLogIn: { $lt: twoDaysAgo } });
});

const options = {
	processEvery: 5000, //ignore
	maxConcurrency: 20,
	lockLimit: 0
};

agenda.every('3 minutes', 'delete old users');

const jobProcessor = new JobProcessor(agenda, options.maxConcurrency, options.lockLimit, options.processEvery);

app.get('/api/cron', (req, res) => {
    jobProcessor.start();

    return res.json({
        success: true
    })
})

This pull request addresses the need for greater flexibility in integrating Agenda.js with serverless architectures and other external triggers (example Vercel environment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant