-1

I have been a laravel developer for 1 year already..Before I used laravel on Windows but since I use Linux..I have a Big problem on Jobs in laravel..every time I start a Job on linux my machine crashes.. but on windows everything works fine.

//my Controller

<?php

namespace App\Http\Controllers;
use App\Jobs\CustomerJob;

use Illuminate\Http\Request;

class SendEmailControllers extends Controller
{
public function sendEmail(){
    dispatch(new CustomerJob())->delay(now()->addMinutes(1));
    dd('Email has been delivered');
}

}

//Job Code

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;
use App\Mail\WelcomeUserMail;

class CustomerJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable,   SerializesModels;

/**
 * Create a new job instance.
 *
 * @return void
 */
public function __construct()
{
    //
}

/**
 * Execute the job.
 *
 * @return void
 */
public function handle()
{
    Mail::to('bramslevel129@gmail.com')->send(new WelcomeUserMail);
}

}

Here is the error that is displayed when I restart the machine. the error is displayed on my Failed_job table..

//error

Illuminate\Queue\MaxAttemptsExceededException: 
App\Jobs\CustomerJob has been attempted too many times or run too long.
The job may have previously timed out.
in /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:750 Stack trace:#0 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(504): Illuminate\Queue\Worker->maxAttemptsExceededException()
#1 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(418): Illuminate\Queue\Worker->markJobAsFailedIfAlreadyExceedsMaxAttempts()
#2 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(378): Illuminate\Queue\Worker->process()
#3 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(172): Illuminate\Queue\Worker->runJob()
#4 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(126): Illuminate\Queue\Worker->daemon()
#5 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(110): Illuminate\Queue\Console\WorkCommand->runWorker()
#6 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Queue\Console\WorkCommand->handle()
#7 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#8 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#9 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#10 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\Container\BoundMethod::call()
#11 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\Container\Container->call()
#12 /home/dev/www/laravel-authentication/vendor/symfony/console/Command/Command.php(291): Illuminate\Console\Command->execute()
#13 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\Component\Console\Command\Command->run()
#14 /home/dev/www/laravel-authentication/vendor/symfony/console/Application.php(989): Illuminate\Console\Command->run()
#15 /home/dev/www/laravel-authentication/vendor/symfony/console/Application.php(299): Symfony\Component\Console\Application->doRunCommand()
#16 /home/dev/www/laravel-authentication/vendor/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun()
#17 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Console/Application.php(102): Symfony\Component\Console\Application->run()
#18 /home/dev/www/laravel-authentication/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\Console\Application->run()
#19 /home/dev/www/laravel-authentication/artisan(37): Illuminate\Foundation\Console\Kernel->handle()
#20 {main}
Level
  • 1
  • 1
  • add job code and how do you run it – Ol D. Castor May 23 '22 at 16:18
  • presumably different PHP settings in regards to timeout/max runtime – Honk der Hase May 23 '22 at 16:48
  • 1
    Welcome to Stack Overflow. [Please don't post screenshots of text](https://meta.stackoverflow.com/a/285557/354577). They can't be searched or copied, or even consumed by users of adaptive technologies like screen readers. Instead, paste the code as text directly into your question. If you select it and click the `{}` button or Ctrl+K the code block will be indented by four spaces, which will cause it to be rendered as code. – ChrisGPT was on strike May 23 '22 at 23:52
  • @OlD.Castor when i run this code on windows it works...but when i'm on linux the whole system doesn't work anymore...i really don't know the real problem...i'm using the latest version of php. – Level May 24 '22 at 10:44
  • @Level check logs (by default in storage/logs folder) – Ol D. Castor May 24 '22 at 11:31
  • - @OlD.Castor Ok thank you I just made an update I sent the errors that are displayed on my Failed_jobs table – Level May 24 '22 at 11:49

1 Answers1

0

try set breaking rules for job to stop hanging your system

//CustomerJob.php
    /**
     * The number of seconds the job can run before timing out.
     *
     * @var int
     */
    public $timeout = 15; // just for your case

    /**
     * Indicate if the job should be marked as failed on timeout.
     *
     * @var bool
     */
    public $failOnTimeout = true;


    /**
     * The number of times the job may be attempted.
     *
     * @var int
     */
    public $tries = 3;
 
    /**
     * The maximum number of unhandled exceptions to allow before failing.
     *
     * @var int
     */
    public $maxExceptions = 1;

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Log::debug('jobs', ['job start']);
        Mail::to('bramslevel129@gmail.com')->send(new WelcomeUserMail);
        Log::debug('jobs', ['job end']);
    }

and check project_folder/storage/logs/laravel.log (if log configured as single file) or corresponding with log config - there can be errors regarding job itself not (failed to send mail because of bad mail config for example)


step 2: try set mail driver to log to see changes and again check logs

# .env file
# you can comment lines using # in this file
# MAIL_MAILER=smtp
MAIL_MAILER=log
MAIL_LOG_CHANNEL=debug
Ol D. Castor
  • 543
  • 4
  • 12
  • - OI D. Castor. in my storage/log folder no important information is displayed just this message [2022-05-24 15:07:03] local.DEBUG: jobs ["job start"] it is the result of the first line of the handle function that you told me to put but no other information is displayed. – Level May 24 '22 at 16:07
  • @Level, does your pc still crash on job launch? – Ol D. Castor May 24 '22 at 18:17
  • - @OI D. Castor My computer crashes but in a short time, I would say after 8 min...the system works when the Job stops working...but the sending of email does not start. I use Mailtrap for the tests of sending mail...I'm going to modify my .env file as you said. When I do a die dump on My Job everything works fine. But when I use sending mail, My Linux system Crashes – Level May 25 '22 at 07:19
  • @Level if 'sending' mail into `log` channel works, than i can't help you more - i'm not so good in linux to fix problems that i didn't 'feel' by myself. I guess you should update question to clarify that problem – Ol D. Castor May 25 '22 at 13:56
  • - @OI D. Castor thank you very much i noticed the same problem when i run an infinite loop...i guess my problem comes from my php configuration...i don't know yet..i just assumed .when i execute an infinite loop in another mini project the system crashes – Level May 25 '22 at 17:02