Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chat-app-workers

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chat-app-workers

This app uses bull.js with is Redis-based queue for Node.

  • 1.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

CHAT APP WORKERS

This app uses bull.js with is Redis-based queue for Node.

STRUCTURE

The main goal is to communicating with external services (slack, autopilot, etc...). This lead to specific structure, made of different queues specific for each service. To call it just return object with queue value equal to corespondent queue name and data as object with method and params.

How to use

Facing all over again same issues we decide to put all hard logic into sequence factory. This allow to build speed up the process of adding new jobs. Let's take a look into this:

CLI

At first install cli:

npm i chat-app-workers-cli -g

and then call generate-workers name, where name is desire name of directory to be created and follow up with selecting type of your new queue.

File structure

generate-workers command will create a directory with 3 files. You need to interact with all of it. At first set name for queue in index.js file. This should be imported from @autopilot/chat-app-core. You don't need to worry about importing it. It'll be done automatically. Then, modify you eventListener.js file if you need any event to catch. Then you are ready to go and write main content inside `processors.js' file.

The processors.js file should be structure this way:

module.exports = {
    // __default__ is key word to name first function to call in queue.
    // All functions takes two arguments, _job_  and _app_ if needed.
    __default__: (job, app) => {
      return {
        queue: queues.slack.name, // if queue is set it will add job with job.data to that queue.
        // Otherwise it will try to add job to self (if nextStep is set)
        params: {
          method: 'chat.postMessage', // method that will be called in queue, with params 
          params: { token: 'xxx' }
        },
        extraData: {
          name: 'name' // this will extend job.data that will be passed to next step (if nextStep is set)
        },
        nextStep: 'secondStep' // next method in THIS queue that will be called
      }
    },
    secondStep: (job) => {
      console.log(job.data) // will have name === 'name' as we passed it in previous extraData value.
      const { res } = job.data // res from external will be passed to job.data in res key.

      return {
        queue: queues.slack.name, // if queue is set it will add job with job.data to that queue.
        // Otherwise it will try to add job to self (if nextStep is set)
        params: {
          method: 'chat.delete', // method that will be called in queue, with params 
          params: {
            token: 'xxx',
            channel: '1',
            ts: '123'
          },
        }
      }
    //this will be last step as nextStep is not set
    }
}

FAQs

Package last updated on 24 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc