Skip to content

Commit

Permalink
Move indexes creation after agenda start on init method in agenda que…
Browse files Browse the repository at this point in the history
…ue service
  • Loading branch information
alejandro-bulgaris-qcif committed Jun 26, 2024
1 parent b088fdd commit 7a8aa43
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions typescript/api/services/AgendaQueueService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ export module Services {
this.setOptionIfDefined(agendaOpts, optionName, optionVal);
});
const dbManager = User.getDatastore().manager;
const collectionName = _.get(agendaOpts, 'collection', 'agendaJobs');
await dbManager.collection(collectionName).createIndex({ name: 1, disabled: 1, lockedAt: 1, nextRunAt: 1 })
await dbManager.collection(collectionName).createIndex({ name: -1, disabled: -1, lockedAt: -1, nextRunAt: -1})
if (_.isEmpty(_.get(agendaOpts, 'db.address'))) {
agendaOpts['mongo'] = dbManager;
}
Expand All @@ -115,6 +112,12 @@ export module Services {
sails.log.error(err);
});
await this.agenda.start();

//Create indexes after agenda start
const collectionName = _.get(agendaOpts, 'collection', 'agendaJobs');
await dbManager.collection(collectionName).createIndex({ name: 1, disabled: 1, lockedAt: 1, nextRunAt: 1 });
await dbManager.collection(collectionName).createIndex({ name: -1, disabled: -1, lockedAt: -1, nextRunAt: -1});

// check for in-line job schedule
_.each(sails.config.agendaQueue.jobs, (job) => {
if (!_.isEmpty(job.schedule)) {
Expand Down

0 comments on commit 7a8aa43

Please sign in to comment.