Skip to main content

Universal Job Queue or UJQ in short is a Redis based Simple MultiPlatform Job management library build. This Library is light weight and build for working with microservices.

Project description

UJQ

Universal Job Queue or UJQ in short is a Redis based Simple MultiPlatform Job management library. This Library is light weight and build for working with microservices. Currently we have Node and Python implementation of Library. C# and Java are in pipeline.

Benifits

  1. Jobs can be created and processed by different application or services
  2. Auto trigger when job is created
  3. Job Completion and error indications

Python

CLICK HERE for Node.js Package

Installing UJQ

You can use PIP to install

pip install ujq

Connecting to Redis

Use the following to connect to redis

from ujq import ujq
import json

UJQ = ujq(host="127.0.0.1",port=6379)
UJQ.connect()
    

Create a new Job

The following Code will create a new Job

id = UJQ.createJob('Test_100',{"test":"test45y76475"})
print(id)
    

On creation of New Job

The Below Code will work on the job and returns a status

def callback (message,complete):
    print(json.dumps(message))
    complete({'status':True,"DummyData":"blablabla"},False)

UJQ.onCreated('Test_100',callback)

In case of error, the false tag can be set as true... Invoking the complete callback will complete the job and will be moved from queue...

On completion of Job

result = UJQ.onCompleted(id)
print(result)

The above code will complete the job.

Run Job

A new method is created for UJQ version 2 and above to run which combines both createJob and onCompleted

result = UJQ.runJob('Test_100',{"test":"test45y76475"})
print(result)

Express with UJQ

A simple implementation of Express in Node.js with UJQ in Python as shown

Create a Server.js with the below code

const express = require("express")
const UJQ = require("ujq")
const ujq = new UJQ({ port: "6379", host: "127.0.0.1" })
const app = express()
const port = 3000

  ujq.connect()
    .then(() => {
        app.get('/', (req, res) => {

            ujq.createJob("test_q2", { test: "sample Data" })

                //Set On Complete
                .then((result) => ujq.onCompleted(result.id))

                //Send Result
                .then((result) => res.send(result))
    })
    
}).catch((e) => console.log(e))

app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))

Now Create Worker.py with the below Code

from ujq import ujq
import json

def callback (message,complete):
    print(json.dumps(message))
    complete({'status':True,"DummyData":"blablabla"},False)

UJQ.onCreated('Test_100',callback)

Run both the files and Enjoy :B

New onError method

This method will handle errors during disconnect of redis in between

UJQ.onError(lambda x:run())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ujq-2.0.1.tar.gz (5.1 kB view details)

Uploaded Source

File details

Details for the file ujq-2.0.1.tar.gz.

File metadata

  • Download URL: ujq-2.0.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.2

File hashes

Hashes for ujq-2.0.1.tar.gz
Algorithm Hash digest
SHA256 3fba2d49f1508817bd0d7b431abe635a26de43db981ebe4aa029d325710501d7
MD5 423425696b4994fa07186b259bec906d
BLAKE2b-256 5c55a02e017036ab632fcd7624e43b1d8f1bdf00ac8c6fee318c483cbef52817

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page