WyriHaximus / reactphp-cron

Cronlike scheduler running inside a ReactPHP Event Loop
MIT License
40 stars 3 forks source link

How to start action immediately? #84

Open hasanparasteh opened 2 weeks ago

hasanparasteh commented 2 weeks ago

Sometimes we need to start long term actions immediately. Is there any solution available for this specific problem? Or should I implement it in a fork?

WyriHaximus commented 2 weeks ago

Well you two options: A) Just run the function you pass it on start up B) I'll add an @startup schedule option to this package

Also I assume you might want to provide @startup and the schedule you already had configured for it? So would also make that possible 👍 .

hasanparasteh commented 2 weeks ago

that would be great if we could have @startup functionality

WyriHaximus commented 2 weeks ago

Not sure if it will be @start up or a dedicated action that provides it yet. But will let you know when the PR is up

hasanparasteh commented 2 weeks ago

I use a package in golang that has similar functionality. it's gocron and maybe we could use their idea. It's easy to use and has similar structure like reactphp-cron. I'd happy if you take a look and let me know, If you decide anything to implement I would be happy to contribute.

for example we could accept some options as arguments just like gocron. It could be like below:

job, err := scheduler.NewJob(
    gocron.DurationJob(
        10*time.Minute,
    ),
    gocron.NewTask(),
    gocron.WithStartAt(gocron.WithStartImmediately()),
)
WyriHaximus commented 2 weeks ago

Public API isn't much of an issue, was looking at was of doing it clean and smart. But might end up doing an instanceof internally to figure out which implementation is used to kick it off right away.

WyriHaximus commented 2 weeks ago

PR is up at https://github.com/WyriHaximus/reactphp-cron/pull/85, not super happy with the naming yet tbh