1

当我将工作分派到 redis 队列时,Laravel 5.7 出现队列工作失败问题。所以有人可以帮忙吗?

public function forgotPassword(Request $request)
{
    $validator = Validator::make($request->all(), [
        'email' => 'required|email',
    ]);
    if ($validator->fails()) {
        return response()->json(['error' => $validator->errors()], 401);
    }
    $input = $request->all();
    $users = User::where('email', $input['email'])
    ->where('is_active', false)
    ->firstOrFail();
    if (!$users) {
        return response()->json(['error' => 'Bad request'], 400);
    }

    $user_id = $users->id;

    $this->dispatch(
        new SendEmailCommand($user_id)
    );

    $success['message'] = 'Your request has been processed successfully. Please check your email.';
    $success['response'] = true;

    return response()->json(['success' => $success], $this->successStatus);
}

这是我的 SendEmailCommand.php

class SendEmailCommand extends Command implements ShouldQueue
{
    use InteractsWithQueue, SerializesModels;
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'wasel-sendEmail:verify{user}';
    public $tries = 3;

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Sending Email to authorized email.';

    /**
     * Create a new command instance.
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $user_id = $this->argument('user');
        $users = User::find($user_id);
        $bar = $this->output->createProgressBar(count($users));
        $email = $users->email;

        try {
            Mail::to($email)->send(new SendEmailMailable());
            $bar->advance();
            Log::info('otp fetched successfully.'.$email);
            //$bar->advance();
        } catch (Exception $e) {
            $this->error('Something went wrong!'.$e->getMessage());
        }

        $message = '--Sending Email through SMTP Command--';
        Log::info($message);
        $bar->finish();
        $this->info('Done!');
        //return $this->release(10);
    }

    /**
     * Determine the time at which the job should timeout.
     *
     * @return \DateTime
     */
    public function retryUntil()
    {
        return now()->addSeconds(10);
    }
}

我也有 Laravel.log 超过最大尝试次数

    [2018-09-26 20:21:54] local.ERROR: App\Console\Commands\SendEmailCommand has been attempted too many times or run too long. The job may have previously timed out. {"exception":"[object] (Illuminate\\Queue\\MaxAttemptsExceededException(code: 0): App\\Console\\Commands\\SendEmailCommand has been attempted too many times or run too long. The job may have previously timed out. at /usr/local/var/www/wasel-jwt/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:401)
[stacktrace]
#0 /usr/local/var/www/wasel-jwt/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(321): Illuminate\\Queue\\Worker->markJobAsFailedIfAlreadyExceedsMaxAttempts('redis', Object(Illuminate\\Queue\\Jobs\\RedisJob), 3)
#1 /usr/local/var/www/wasel-jwt/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(277): Illuminate\\Queue\\Worker->process('redis', Object(Illuminate\\Queue\\Jobs\\RedisJob), Object(Illuminate\\Queue\\WorkerOptions))
#2 /usr/local/var/www/wasel-jwt/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(118): Illuminate\\Queue\\Worker->runJob(Object(Illuminate\\Queue\\Jobs\\RedisJob), 'redis', Object(Illuminate\\Queue\\WorkerOptions))
#3 /usr/local/var/www/wasel-jwt/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(102): Illuminate\\Queue\\Worker->daemon('redis', 'default', Object(Illuminate\\Queue\\WorkerOptions))
#4 /usr/local/var/www/wasel-jwt/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(86): Illuminate\\Queue\\Console\\WorkCommand->runWorker('redis', 'default')
#5 [internal function]: Illuminate\\Queue\\Console\\WorkCommand->handle()
#6 /usr/local/var/www/wasel-jwt/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#7 /usr/local/var/www/wasel-jwt/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#8 /usr/local/var/www/wasel-jwt/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#9 /usr/local/var/www/wasel-jwt/vendor/laravel/framework/src/Illuminate/Container/Container.php(564): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#10 /usr/local/var/www/wasel-jwt/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\\Container\\Container->call(Array)
#11 /usr/local/var/www/wasel-jwt/vendor/symfony/console/Command/Command.php(251): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#12 /usr/local/var/www/wasel-jwt/vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#13 /usr/local/var/www/wasel-jwt/vendor/symfony/console/Application.php(886): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#14 /usr/local/var/www/wasel-jwt/vendor/symfony/console/Application.php(262): Symfony\\Component\\Console\\Application->doRunCommand(Object(Illuminate\\Queue\\Console\\WorkCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#15 /usr/local/var/www/wasel-jwt/vendor/symfony/console/Application.php(145): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#16 /usr/local/var/www/wasel-jwt/vendor/laravel/framework/src/Illuminate/Console/Application.php(89): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#17 /usr/local/var/www/wasel-jwt/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#18 /usr/local/var/www/wasel-jwt/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#19 {main}
"} 

我也尝试将 queue.php failed_job 连接更改为 redis

'failed' => [
        'database' => env('DB_CONNECTION', 'mysql'),
        'table' => 'failed_jobs',
    ],

我已尝试运行此作业,但无法运行此作业。请帮帮我?

4

0 回答 0