1

I have scheduled command php artisan charge:debts which has every minute scheduling option, but the problem it doubles the API request every time.

My Kernel.php:

$schedule->command('charge:debts')->everyMinute();

My console command function:

$active_debts = Debt::where([['status', '=', 0]]) -> with('channels') -> get();
foreach($active_debts as $debt) {
 try {
        $stripe = new \Stripe\StripeClient(env('STRIPE_CODE'));
        $stripe->transfers->create([
            'amount' => $transfer_amount,
            'currency' => $currency,
            'destination' => 'XXXXXX',//acct_1GqQxFH4ie1ley5J
            'transfer_group' => 'Pltaform fees',
        ], ['stripe_account' => $merchant_code]);

        Debt::where('id', $debt->id) -> update([
            'status' => 1
        ]);
    } catch(\Stripe\Exception\InvalidRequestException $e) {
...
    }
}

Maybe someone can help how to avoid callng $stripe->tranfers->create two times? There is only one 'Debt' with status = 0 in the database :)

Adrijus Jakučionis
  • 265
  • 1
  • 3
  • 12
  • How many servers do you have for your application. If they are two servers and you are running the cronjob on both of them it will trigger the console command twice. If you are using Redis you can add $schedule->command('charge:debts')->everyMinute()->onOneServer(); – Emil Georgiev Nov 03 '21 at 08:07

0 Answers0