Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

323
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda