Agenda - v6.0.0
    Preparing search index...

    Function Define

    • Method decorator that defines a job handler.

      Jobs decorated with

      Parameters

      • options: DefineOptions = {}

        Configuration options for the job definition

      Returns (
          target: any,
          propertyKey: string,
          descriptor: PropertyDescriptor,
      ) => PropertyDescriptor

      Method decorator

      must be scheduled programmatically using agenda.now(), agenda.schedule(), or agenda.every().

      import { JobsController, Define, Job } from 'agenda';

      @JobsController()
      class EmailJobs {
      @Define({
      name: 'sendWelcome',
      concurrency: 5,
      priority: 'high'
      })
      async sendWelcomeEmail(job: Job<{ userId: string; template: string }>) {
      const { userId, template } = job.attrs.data;
      await this.emailService.send(userId, template);
      }
      }

      // Later, schedule the job:
      await agenda.now('sendWelcome', { userId: '123', template: 'welcome' });