GithubHelp home page GithubHelp logo

Use Websockets in Tasks about adonis-scheduler HOT 4 OPEN

nrempel avatar nrempel commented on May 26, 2024
Use Websockets in Tasks

from adonis-scheduler.

Comments (4)

nrempel avatar nrempel commented on May 26, 2024

Connections must be made from a web process since the scheduler process does not run a web server.

I suggest using something like Redis to send a message from the scheduler process(es) to the web process(es). Then, the web process can send a websocket message to the client.

https://adonisjs.com/docs/4.1/redis#_pub_sub

from adonis-scheduler.

ntvsx193 avatar ntvsx193 commented on May 26, 2024

You can try use AdonisJS Events for send event to WS.
I use it in adonis version 3.2

from adonis-scheduler.

AudyOdi avatar AudyOdi commented on May 26, 2024

Hi @ntvsx193, could you explain more about what was your approach to send event to WS? I tried using AdonisJS Events too when initializing the socket and but keep getting undefined when I want to broadcast the message, even after the initialization happened.

// start/events.js
Event.on('cardPrice::initialize', (socket) => {
  wsSocket = socket;
  console.log('wsSocket', wsSocket);
});

Event.on('cardPrice::update', async (newCardPriceList) => {
  console.log('wsSocket update', wsSocket); << keep getting undefined even after initialize happened
});


// app/Controller/WS/UpdateCardPriceController.js
class UpdateCardPriceController {
  constructor({socket, request}) {
    this.socket = socket;
    this.request = request;
    Event.fire('cardPrice::initialize', socket);
    console.log('a new subscription for cardPrice topic');
  }
}

from adonis-scheduler.

MatheusVSMPimentel avatar MatheusVSMPimentel commented on May 26, 2024

@AudyOdi
I been have this Issues too while I trying to make a database connect in WebSocketController
I been thinking in maybe making a service provider and using is I can over this stack

from adonis-scheduler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.