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

How to manage schedulers programmatically in a web environment #8

Open
h25302 opened this issue Mar 2, 2024 · 6 comments
Open

How to manage schedulers programmatically in a web environment #8

h25302 opened this issue Mar 2, 2024 · 6 comments

Comments

@h25302
Copy link

h25302 commented Mar 2, 2024

I want to adjust parameters programmatically and run and stop the scheduler at (environment: ['web'])

@KABBOUCHI
Copy link
Owner

KABBOUCHI commented Mar 2, 2024

you can access the scheduler instance, and modify/add wtvr u want here

import scheduler from 'adonisjs-scheduler/services/main'

scheduler.command("inspire").everyFiveSeconds();

scheduler.items // u can access all added commands here

and probably u need a custom logic, check how its done here https://github.com/KABBOUCHI/adonisjs-scheduler/blob/master/commands/scheduler_command.ts

@h25302
Copy link
Author

h25302 commented Mar 3, 2024

How can I stop and start (scheduler.items|item) programmatically

Similar to the following:
scheduler.stopAll()
scheduler.runAll()
scheduler.item[0].stop()
scheduler.item[0].run()
scheduler.item[0].delete()

Thank you very much, @KABBOUCHI

@rbartholomay
Copy link

i have the same question. Inside the adonisrc.ts i add 'web'. But how start the scheduler when the application boots?

    {
      file: () => import('adonisjs-scheduler/scheduler_provider'),
      environment: ['console', 'web'],
    }

Bye, René

@mattsimonis
Copy link

Here is how I ended up approaching this:

  • Updating the provider to add web, like you did.
  • In the server.ts file, adding this block within the tap callback:
app.ready(async () => {
  await import('#start/scheduler');

  const ace = await app.container.make('ace');
  await ace.exec('scheduler:run', []);
});

@rbartholomay
Copy link

Nice! Thank you very much!

@h25302
Copy link
Author

h25302 commented Oct 19, 2024

Thank you very much! @mattsimonis

"Scheduler: Run" is fine, but how do I stop it?
How to use programming to control it?

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

No branches or pull requests

4 participants