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