Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev-mode Suggestion #39

Open
mattstrayer opened this issue Jun 2, 2024 · 4 comments
Open

Dev-mode Suggestion #39

mattstrayer opened this issue Jun 2, 2024 · 4 comments

Comments

@mattstrayer
Copy link

The option to run the jobs synchronously in development would be really nice.

Is this possible with the current state of the package?

@RomainLanz
Copy link
Owner

Yup, it could be doable, same with #20

@mattstrayer
Copy link
Author

For now I just made a BaseJob that all other jobs inherit from

import Application from '@ioc:Adonis/Core/Application'
import { JobHandlerContract, Queue, type Job } from '@ioc:Rlanz/Queue'

export default class BaseJob implements JobHandlerContract {
  // needs to be implemented in each job, imports cannot be inherited properly
  public static get $$filepath(): string {
    // must be implemented by subclass
    throw new Error('Must be implemented by subclass')
  }

  constructor(public job: Job) {
    this.job = job
  }

  public static async run(payload) {
    const job = new this(payload)

    if (Application.inDev) {
      job.handle(payload)
    } else {
      Queue.dispatch(this.$$filepath, payload)
    }
  }

  /**
   * Base Entry point
   */
  public async handle(payload: any) {}

  /**
   * This is an optional method that gets called if it exists when the retries has exceeded and is marked failed.
   */
  public async failed() {}
}

so I'll just call the class method of SomeJob.run() and that will either queue it up or run it synchronously.

@RomainLanz
Copy link
Owner

RomainLanz commented Jun 12, 2024

What do you think of having a flag in the configuration?

defineConfig({
  instant: true // or immediate or sync or ...
})

(I am not sure about the name)

@mattstrayer
Copy link
Author

I like that approach! Easily configurable per environment which would be great :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants