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

Feature: RunAll by tag #143

Closed
bobmcallan opened this issue Mar 23, 2021 · 5 comments · Fixed by #149
Closed

Feature: RunAll by tag #143

bobmcallan opened this issue Mar 23, 2021 · 5 comments · Fixed by #149
Labels
enhancement New feature or request

Comments

@bobmcallan
Copy link

bobmcallan commented Mar 23, 2021

At program startup, it is common to execute a job then enter the schedule. It would be great to execute a selection of jobs (by tag?) at startup.

`

scheduler = gocron.NewScheduler(time.UTC)

scheduler.Every(5).Minutes().SingletonMode().Do(p.users, false)
scheduler.Every(30).Minutes().SingletonMode().Tag("startup").Do(p.users, true)

scheduler.StartAsync()

// Execute @ Startup
for j := range scheduler.Tag("startup").Jobs(){
    j.RunOnce()
}

// or Execute @ Startup	
scheduler.Tag("startup").RunAllWithDelay(10 * time.Second)

`

@bobmcallan bobmcallan added the enhancement New feature or request label Mar 23, 2021
@JohnRoesler JohnRoesler changed the title RunAll by tag Feature: RunAll by tag Mar 24, 2021
@JohnRoesler
Copy link
Contributor

How about we had a function similar to run all with delay? RunByTagWithDelay(time.Duration)

@bobmcallan
Copy link
Author

bobmcallan commented Mar 25, 2021

Yes, RunByTagWithDelay(time.Duration, tag) would work.

However, I'm in setting up a scheduler, I've noticed that scheduler.StartAsync() runs all the jobs immediately, and then on schedule.

i.e.

scheduler.Every(5).Minutes().Do(tablecount)
scheduler.StartAsync() 

Executes the jobs and then every 5 minutes post the StartAsync.

Is this by design?

@JohnRoesler
Copy link
Contributor

correct - by design all jobs are run once the scheduler is started.

@JohnRoesler
Copy link
Contributor

@bobmcallan we added support in the form of two new methods:

  • RunByTag
  • RunByTagWithDelay

Checkout #149 for more details. We'll get it released soon.

@JohnRoesler
Copy link
Contributor

This is out in release v1.2.0

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

Successfully merging a pull request may close this issue.

2 participants