Updating payment status using Cron in the Standard

Asked

Viewed 28 times

-3

I have the following scenario: I am using a payment api where each order expires in 15 minutes, how can I register a cron task for each payment order I have, bad I know where to start I am using Laravel 8.

2 answers

1

The way is to implement an Artisan command in your application that when executed expires payments, say its name is expirar-pagamentos

Then you create a Schedule entry in the file App\Console\Kernel, within the method protected function schedule(Schedule $schedule) you will make the call of this command, the ideal every 1 minute, the logic of the command is that it should analyze if it has passed 15 min of the payment order.

Example:

class Kernel extends ConsoleKernel
{
    /**
     * demais código da classe
     */

    ... 

    protected function schedule(Schedule $schedule)
    {
        $schedule->command('expirar-pagamentos')->everyMinute();
    }
}

Finally you must add the call line of the scheduler command of your Laravel project in the system cron

* * * * * cd /caminho-do-seu-projeto && php artisan schedule:run >> /dev/null 2>&1

To add this line in cron you can use the command crontab -e to open the cron file command line editor.

-2

The question is quite widespread, but what you want to do in the Standard is called Task Scheduling. The documentation of how to use it is below: https://laravel.com/docs/8.x/scheduling

but I guess you’d have to write a script and run it that way:

$Schedule->exec('Node /home/Forge/script.js')->tempo()*;

  • first would be every 5 minutes, second every 10 and third every 15 minutes ->everyFiveMinutes(); Run the task Every five minutes ->everyTenMinutes(); Run the task Every ten minutes ->everyFifteenMinutes(); Run the task Every Fifteen minutes

Browser other questions tagged

You are not signed in. Login or sign up in order to post.