go-co-op / gocron

Easy and fluent Go cron scheduling. This is a fork from https://github.com/jasonlvhit/gocron
MIT License
5.61k stars 308 forks source link

[FEATURE] - Support for Long-Running, One-Time Jobs with Start/Stop Controls #612

Open CR7273868 opened 12 months ago

CR7273868 commented 12 months ago

Is your feature request related to a problem? Please describe I'm experiencing challenges with managing long-running jobs that only need to run once and require frequent start/stop interventions, potentially from an external trigger like a Discord command. The current workaround using every(1).seconds().limitrunsto(1) feels cumbersome and somewhat unreliable, especially for jobs that have longer runtimes. Think about premature exits from job context done channel.

Describe the solution you'd like I would like a feature that allows for more intuitive handling of these types of jobs. Ideally, this feature would enable a job to start and stop based on external triggers while ensuring that it runs to completion unless explicitly cancelled. This would involve better integration with job context, allowing for graceful handling of job.ctx.Done() without premature termination.

Describe alternatives you've considered The current alternative involves using a combination of every(1).seconds().limitrunsto(1) and manual intervention, but this is not optimal for our use case. It lacks the finesse and control required for efficiently managing long-running, one-time jobs.

Additional context This feature would be particularly useful in scenarios where jobs are controlled by non-technical team members or through automated triggers from various platforms like Discord. It would enhance the flexibility and usability of gocron in more complex job scheduling scenarios.

JohnRoesler commented 10 months ago

Hey @Demy076

This may notcompletely solve your request - but v2 now has OneTimeJobs.

With this you could trigger your runs, and then if failed, run again with Job.RunNow -> example