laravel task scheduling from database

Published 2 years ago by lorvent

Hi, I am building a service where people can register to fetch API at regular intervals like 5mins, 15mins etc

and since every person uses a different schedule, i can't manually write all scheduling into kernel.php

is there any way to utilize database for task scheduling?

any help is appreciated.


Does your client call your api every specific minutes right? I think its no need to use laravel schedule service. I think It's just be a simple javascript loop with setTimeout().


if i have 100 subscribers and each subscriber sets their own time, i can't make use of javascript


If i understand your problem correctly, Try this:

protected function schedule(Schedule $schedule)
    $schedule->call(function () {
        $schedules = UserFetchSchedule::whereRaw('DATE_ADD(last_fetched_at, INTERVAL wait_minutes MINUTE) > now()')->get();
        foreach($schedules as $schedule) {
            // Do your api stuffs here.

Thanks, i will try this and update the post.

Please sign in or create an account to participate in this conversation.