@technogise/rn-background-queue-processor

2.0.0 • Public • Published

CircleCI Coverage Status npm version

React Native Queue Processor

A package with the help of which users will be able to add and process different kind of jobs in a queues with background persistent queue processing

Prerequisite

This package does not have any prerequisites that need to be installed.

Features

  • A React Native Queue Processor with persistent queues using rn-background-queue-processor-realm-adapter
  • Jobs will be executed according to priorities using the queues.
  • Job will retry until the failed count matches job's number of retry attempts with retryInterval.
  • Has functionality for Worker instances as well.
  • Background Persistent queue processing using WorkManager.
  • It also plays well with Workers so your jobs can be thrown on the queue, then processed in dedicated worker threads for improved processing performance.
  • Failed Jobs can also be processed.

Compatibility

While we ensure to keep the library updated with newer and improved upcoming releases for React Native, our current version works well for React Native: v0.62.1

Installation steps

npm i @technogise/rn-background-queue-processor

Usage

constructor(dbAdapter) {
         this.adapter = dbAdapter;
     }

The dbAdapter here is an additional feature with which we enable our developers to use this queue with any db of their choice.

  • enqueue(job): Enqueues the job in the queue

  • dequeue(): Dequeues the job from queue on successful execution

  • peek(): To get the top job from Queue

  • getSize(): Returns the length of Queue

  • getItems(): Gives all items of Queue

  • failedJobsEnqueue() Enqueue all the Failed Jobs for processing

  • Adapter

    It is an abstract class which needs to be implemented by users of this package for easy use of any database for storing and processing the queues.

    For the easier understanding and reference, we have added an InMemoryAdapter.js. Here is a list of all functions available in the Adapter class which can be used,

    • getAllItems(): To get all jobs in current queue
    • remove(): Method to remove a job from current queue
    • addItem(item): Method to add a job in the current queue
    • getLength(): Method to get length of current queue
    • getTopItem(): Method to get the current job for processing
    • addFailedItems() Method to add failed items
  • Job While Job class has methods to get id, name and param of current job, we have made the execute, jobSuccess and jobFail function to be abstract for the developer so that he/she decides what to do on execute call.

    The execute method can be used for performing the action in current job. For example, if the current job is an API call then developer can add the steps to fetch data from API in this execute ,method.

    The jobSuccess method tells the developer defined action that needs to be taken if the API response is 200.

    The jobFail method tells the developer defined action that needs to be taken if the API response is 4XX.

  • Worker

    Worker class is a singleton class. In this class, user can process queue using process()

  • Communication with native

    • Process function in worker class schedule a job(STARTPROCESSINGJOB) which calls native module
    • Native module emits events which are listened on the Js side, based on the event emitted queueProcessor will start processing.

Made with ❤️ from Technogise

You can explore our other works on GitHub

Package Sidebar

Install

npm i @technogise/rn-background-queue-processor

Weekly Downloads

1

Version

2.0.0

License

ISC

Unpacked Size

150 kB

Total Files

30

Last publish

Collaborators

  • anand.agrawal
  • anchalsrivastava04
  • prathamudeshmukh
  • varun03