Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

328
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!