V8: how to start QueueableJob programmatically

I want to add all site users to a group by clicking a button on a Dashboard page (in my package). I have a QueueableJob class in my_package/jobs/add_users.php with all the required logic. I install the job following this:


but it doesn’t say how to run it programmatically.

How do I start the QueueableJob? Do I just instantiate the AddUsers class, pass a group ID to its constructor and run its ‘start’ method? Or is there another mechanism of starting jobs programmatically?

Looks like this works:

$job = $this->app->make(AddUsers::class);

What do you mean by running it programmatically?
What triggers the cron?

For example, if it’s dashboard or some kind of admin menu, you could just use automated job dashboard…, or you could copy the necessary code from dashboard’s automated job.

We’ve done the similar customization for customizing PortlandLab’s static site exporter enterprise add-on.

If it’s CLI base, you could just make a automated job, then run the command to run.

I want to start the job by clicking an ‘Add Users’ button on one of my package Dashboard pages. Although the same can be done by clicking the ‘run’ button on the Automated Job page or through the CLI, I want it started from my page.

@linuxoid I’ve implemented the same thing before.
I just copied the codes from core automated job and made it work.