Laravel 广播事件仍在实时处理

问题描述

我是广播的新手,并根据此处的 Laravel 说明进行设置: https://laravel.com/docs/8.x/broadcasting

我正在使用 Pusher,并且已经设置好并且可以正常工作。

我创建了一个事件并将我需要执行的函数放在构造函数中。

namespace App\Events;

use App\Models\CSV_Processing;
use App\Services\BigApiService;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;


class CSVProcessingEvent implements ShouldBroadcast
{
    use Dispatchable,InteractsWithSockets,SerializesModels;

    public $status;
    public $product_category_id;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($product_category_id,$file_name)
    {
        $this->status = 'success';
        $this->product_category_id = $product_category_id;
        $url = env('BIG_API_URL');
        $bigApiService = new BigApiService($url);
        $category = $bigApiService->get("v1/products/categories/$product_category_id")->data;
        $file_errors = CSV_Processing::process_csv_file($product_category_id,$file_name,$category,$bigApiService);
        if(!empty($file_errors))
        {
            CSV_Processing::create_error_log($fileName,$file_errors);
            $this->status = 'error';
        }
            
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('csv-processing-channel');
    }
}

当事件函数完成时,我在 Pusher 控制台中得到请求的输出,但浏览器在函数处理而不是在后端运行时正在旋转。

我可以发布 Laravel 教程所需的任何其他文件,这些文件有助于故障排除。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)