This repository has been archived by the owner on Sep 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: define and create jobs using
@hokify/agenda
- Loading branch information
Showing
6 changed files
with
63 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,32 @@ | ||
// Packages | ||
import Agenda from 'agenda' | ||
import { Agenda } from '@hokify/agenda' | ||
import mongoose from 'mongoose' | ||
|
||
const agenda = new Agenda() | ||
|
||
agenda.mongo(mongoose.connection, 'agenda-jobs') | ||
// Configure Agenda | ||
const agenda = new Agenda({ | ||
ensureIndex: true, | ||
processEvery: '1 minute', | ||
mongo: mongoose.connection | ||
}) | ||
|
||
// Import jobs | ||
import jobs from './jobs/index.js' | ||
|
||
// Define jobs | ||
for (const job in jobs) agenda.define(job.name, job.handler) | ||
for (const jobInfo of Object.values(jobs)) agenda.define(jobInfo.name, jobInfo.handler) | ||
|
||
const graceful = async () => { | ||
await agenda.stop() | ||
process.exit(0) | ||
} | ||
|
||
process.on('SIGTERM', graceful) | ||
process.on('SIGINT', graceful) | ||
|
||
async function start() { | ||
await agenda.start() | ||
for (const jobInfo of Object.values(jobs)) await agenda.every(jobInfo.every, jobInfo.name) | ||
} | ||
await start() | ||
|
||
export default agenda |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
const name = 'process-loan-interests' | ||
|
||
const handler = async (job, done) => { | ||
console.log('i ran!') | ||
|
||
const { Loan } = job.context.models | ||
|
||
// TODO: Process loan interests | ||
|
||
done() | ||
} | ||
|
||
export default { name, handler } | ||
const every = '* * * * *' | ||
|
||
export default { name, handler, every } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters