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 build. 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

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.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

ujq-2.0-py3-none-any.whl (5.8 kB view hashes)

Uploaded Python 3

Supported by

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