Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
fix(temp): create new connection using agenda's builtin driver
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwigoric committed Nov 23, 2023
1 parent ae678c2 commit 5a144f0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/db/conn.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mongoose from 'mongoose'

// Default MongoDB URI
const DEFAULT_MONGODB_URI = 'mongodb://localhost:27017/unboundmnl-problem-area-2'
import { DEFAULT_MONGODB_URI } from './default_uri.js'

class Database {
/**
Expand Down
1 change: 1 addition & 0 deletions src/db/default_uri.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DEFAULT_MONGODB_URI = 'mongodb://localhost:27017/unboundmnl-problem-area-2'
19 changes: 11 additions & 8 deletions src/schedules/agenda.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Packages
import { Agenda } from '@hokify/agenda'
import mongoose from 'mongoose'

// Default MongoDB URI
import { DEFAULT_MONGODB_URI } from '../db/default_uri.js'

// Configure Agenda
const agenda = new Agenda({
ensureIndex: true,
processEvery: '1 minute',
mongo: mongoose.connection
processEvery: '10 minutes',
db: { address: process.env.MONGODB_URI || DEFAULT_MONGODB_URI }
// TODO: Use existing mongoose connection
})

// Import jobs
Expand All @@ -23,10 +26,10 @@ const graceful = async () => {
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()
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
4 changes: 1 addition & 3 deletions src/schedules/jobs/loan-interests.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const name = 'process-loan-interests'

const handler = async (job, done) => {
console.log('i ran!')

const { Loan } = job.context.models

// TODO: Process loan interests

done()
}

const every = '* * * * *'
const every = '0 0 * * *' // Every 12:00 AM

export default { name, handler, every }

0 comments on commit 5a144f0

Please sign in to comment.