راکت
مهدی
مهدی
5 سال پیش توسط مهدی مطرح شد
0 پاسخ

task در لاراول

سلام خدمت همه دوستان عزیز بنده به یه مشکلی خوردم وقتی که یک command ایجاد می کنم و بعد داخل کرنل تعریف میکنم که این command هر روز اجرا بشه هیچ مشکلی برای من پیش نمیاد و هرروز اون command که درست کردم اجرا میشه ولی وقتی یک job تعریف میکنم و بعد داخل kernel تعریفش میکنم هیچ اروری ندارم ولی اصلا اون کاری که اون job باید انجام بده رو نمیده اینم از کدهام

<?php

namespace App\Jobs;

use App\Models\Article;
use App\Models\Product;
use App\Models\User;
use Exception;
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\Log;
use Illuminate\Support\Facades\Redis;

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

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        // $this->user = $user;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {

        Product::create([
            'title' => 'Political',
            'price' => 400,
        ]);

        // sleep(1);
        // // throw new Exception('salam');

        // var_dump('your welcom' . $this->user->name);
    }

    // public function retryUntil()
    // {
    //     return now()->addSeconds(20);
    // }

    // public function failed()
    // {
    //     Log::error(self::class . 'salam chetori');
    // }

}

و اینم از kernel

<?php

namespace App\Console;

use App\Jobs\SendEmail;
use App\Jobs\Welcome;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
       Commands\test::class,
       Commands\SendEmail::class,

    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')->hourly();
        $schedule->command('mahdi:test')->everyMinute();
        $schedule->job(new Welcome)->everyMinute();

    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

و وقتی که دستور php artisan schedule:run رو وارد میکنم command بدون مشکل اجرا میشه ولی Job من خیر

PS C:\xampp\htdocs\laravelRel> php artisan schedule:run
Running scheduled command: "C:\xampp\php\php.exe" "artisan" mahdi:test > "NUL" 2>&1
Running scheduled command: App\Jobs\Welcome