coravel icon indicating copy to clipboard operation
coravel copied to clipboard

Schedule invocable at specific DateTime

Open mihaimyh opened this issue 2 years ago • 2 comments

I was looking into how I can schedule an invokable at a specific DateTime in the future, but I can't find an api for this except the Cron(string cronExpression) method. The inconvenience of using this method is that it expects a specific cron formatted string. Is there an api to convert DateTime to cron expressions?

My use case for such a request is to schedule external API calls to refresh some expired passwords, knowing the DateTime when the passwords will be renewed by parsing the API response body.

mihaimyh avatar Aug 10 '21 14:08 mihaimyh

No, that doesn't exist.

What you could do is create a database table, for example, store the date of when a particular API call + other needed data needs to be triggered.

Have an invocable scheduled for every minute/hour/whatever that will check that table. If the current time is after the time in any of those DB records, then do the API call for that record and remove the record upon success.

Something like that might work?

jamesmh avatar Aug 10 '21 19:08 jamesmh

It doesn't seems that efficient to pool a database every minute. Instead I've create a PR to implement this https://github.com/jamesmh/coravel/pull/247

mihaimyh avatar Aug 11 '21 08:08 mihaimyh