2 months ago

Schedule task exist before completing task

Posted 2 months ago by elo

Hey guys, I have this weird scenario where a scheduled task exist before completing in a laravel 6 project.

My intention is to have a couple of rows updated in my database if certain conditions is met with this code

$schedule->call(function () {

            // get due contributions
            Contribution::where('status', 'due')->chunk(20, function ($dueContributions) {

                foreach ($dueContributions as $contribution) {

                    // get contribution own
                    $user = $contribution->user;

                    // get usr wallet balance
                    $walletBalance = $this->getWalletBalance($user);

                    if ($walletBalance >= $contribution->contribution)
                        $this->autoWalletDebit($contribution, $user, $walletBalance);

            Log::notice('Wallet auto contribution complete.');
        })->everyFiveMinutes()->description('Automatic wallet thrift contribution.');

I noticed from my telescope that the task runs but ends almost immediately. So before running the first time, there were 56 rows that met this condition. After running the first time, only 16 rows were updated, the second time only 7 rows were updated.

I have no clue why this is the case or how else to make it run completely before exisitng. Can anyone tell me why or how to fix it?

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