Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Websocket emit doesn't work in Jobs #482

Open
gitlky opened this issue Apr 15, 2021 · 4 comments
Open

Websocket emit doesn't work in Jobs #482

gitlky opened this issue Apr 15, 2021 · 4 comments

Comments

@gitlky
Copy link

gitlky commented Apr 15, 2021

Make sure you read Issues Guideline and answer these questions before submitting your issue. Thanks!
(Any non-English issues will be closed immediately.)

  1. Please provide your PHP and Swoole version. (php -v and php --ri swoole)
PHP 7.4.16 (cli) (built: Mar  6 2021 04:24:10) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.6.5
Built => Apr 14 2021 20:52:21
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
spinlock => enabled
rwlock => enabled
zlib => 1.2.11
brotli => E16777225/D16777225
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
  1. Please provide your Laravel/Lumen version.
Laravel Framework 8.37.0
  1. Which release version of this package are you using?
^2.8
  1. What did you do? If possible, provide a recipe for reproducing the error.
<?php

namespace App\Jobs;

use Log;
use Illuminate\Bus\Queueable;
use Illuminate\Console\Command;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use SwooleTW\Http\Websocket\Facades\Websocket;

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

    public function __construct()
    {
       Log::info('coming');
    }

    public function handle()
    {

        Websocket::broadcast()->emit('starting',[]);
    }
}
  1. What did you expect to see?

I hope the websokct:emit () work in jobs

  1. What did you see instead?

it can't work

@Arkanius
Copy link
Contributor

Are you using socket.io?

@gitlky
Copy link
Author

gitlky commented Apr 21, 2021

@Arkanius i'm using websockt

@gitlky
Copy link
Author

gitlky commented Apr 21, 2021

I wanna notify all online websocket user do something after the queue job finish;
I'm sure the queue job is worked,because the log is printed, and client was Connected;
but the all websocket client dose't received message from server

In a nutshell:
Websocket::broadcast()->emit('starting',[]);
work in Controller,
inoperation in Queue Job
GenBarcodeJob::dispatch();

@ZYY-XU
Copy link

ZYY-XU commented Apr 8, 2022

我想在队列作业完成后通知所有在线 websocket 用户做一些事情; 我确定队列作业有效,因为打印了日志,并且客户端已连接; 但是所有 websocket 客户端都没有收到来自服务器的消息

简而言之: Websocket::broadcast()->emit('starting',[]); 在Controller中 工作,在Queue Job中不操作 GenBarcodeJob::dispatch();

Friend, has your problem been solved?

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

3 participants