Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

324
Visualizações
Web socket.io with AdonisJs not working properly

Web socket.io with AdonisJs not working properly.

I'm using a lib to perform tasks inside adonis, adonis5-scheduler.

Below is my task.

import { BaseTask } from 'adonis5-scheduler/build'

export default class GetRouletteGame extends BaseTask {
    public static get schedule() {
        return '*/3 * * * * *'
    }
    /**
     * Set enable use .lock file for block run retry task
     * Lock file save to `build/tmpTaskLock`
     */
    public static get useLock() {
        return false
    }

    public async handle() {
      Ws.io.emit(`taskName`, 1)
      console.log('ok')
    }
}

Below is my Ws.

import { Server } from 'socket.io'
import AdonisServer from '@ioc:Adonis/Core/Server'

class Ws {
  public io: Server
  private booted = false

  public boot() {
    /**
     * Ignore multiple calls to the boot method
     */
    if (this.booted) {
      return
    }

    this.booted = true
    this.io = new Server(AdonisServer.instance!, {
      cors: {
        origin: '*'
      }
    })
  }
}

export default new Ws()

Calling Ws.io.emit from the controller works.

Calling Ws.io.emit from the task doesn't work.

Note for the task Ws.io.emit does not work, however the console.log displays the message.

Task does not run Ws.io.emit

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Resolved

await fetch('http://127.0.0.1:3333/endpoint' to control

From the controller I called emit and it worked.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda