Skip to content

Documentation: Where and when should JobScheduler.schedule() be called? #90

@henriquealbert

Description

@henriquealbert

The documentation shows how to use JobScheduler.schedule() but doesn't explain where to call it or which AdonisJS environment to use.

Should scheduled jobs be set up in a preload file? If so, which environment?

Current Approach (uncertain if correct)

// start/scheduler.ts
 import app from '@adonisjs/core/services/app'
 import { JobScheduler } from '@nemoventures/adonis-jobs'
 import MyJob from '#jobs/my_job'

 app.ready(async () => {
   await JobScheduler.schedule({
     key: 'my-scheduled-job',
     job: MyJob,
     data: {},
     repeat: { pattern: '0 * * * *' },
   })
 })
  // adonisrc.ts
  preloads: [
    {
      file: () => import('#start/scheduler'),
      environment: ['console'], // ← Is this correct?
    },
  ]

What needs clarification

  1. Is using a preload file the recommended approach?
  2. Should environment: ['console'] be used, or no environment restriction?
  3. Is JobScheduler.schedule() idempotent (safe to call multiple times)?
  4. In multi-process deployments (separate web/worker containers), where should schedules be registered?

Suggested addition

A "Scheduling Jobs" guide section covering the recommended setup pattern and environment configuration would be very helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions