Execute Laravel Function at a Specified Time

How can a function be set to run at a time specified to insert data to a database (date and time)?

When I save data January 30, 2017. The function will run at January 30, 2017,

When I create another data February 01, 2017, then the function will run at February 01, 2017 too.

I tried using Laravel's scheduler but its time must be specified statically, not dynamically, I need a dynamic one so I can customize my date setting.

I tried using Laravel's queue (jobs) but it doesn't have date setting.

Upvotes: 2

Views: 1670

Answers (2)

Raunak Gupta
Raunak Gupta

Reputation: 10809

Here is the code which will run on January 30, 2017.

//file path: app/Console/Kernel.php
class Kernel extends ConsoleKernel {

    //other code

    protected function schedule(Schedule $schedule) {
        $schedule->command('my_command')
                ->withoutOverlapping()
                ->cron('0 0 30 1 0 2017');
    }
}

and for February 01, 2017

->cron('0 0 1 2 0 2017')


Reference:

Upvotes: 2

Komal
Komal

Reputation: 2736

Use Cron is a time-based job scheduler in Unix-like computer operating systems.

Upvotes: 0

Related Questions