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

github.1git.de/jorbriib/multiple-job-queue

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.1git.de/jorbriib/multiple-job-queue

  • v1.0.0
  • Go
  • Socket score

Version published
Created
Source

Go Report Card Build Status

Multiple Job Queue provides an API to process jobs in asynchronous way. Also, it allows you to defer the processing of a time-consuming task and creates a number of workers to parallelize the execution of each job.

Installation

The routing package is just a common Go module. You can install it as any other Go module.

go get github.com/jorbriib/multiple-job-queue

To get more information just review the official Go blog regarding this topic.

Usage

This is just a quick introduction, view the GoDoc for details.

Basic usage example in a web server:

package main

import (
    mjq "github.com/jorbriib/multiple-job-queue"
    "fmt"
    "log"
    "net/http"
    "time"
)
type TestJob struct {
}

func (tj *TestJob) Handle() {
    time.Sleep(2 * time.Second)
    fmt.Println("Job handled")
}

func handler(w http.ResponseWriter, r *http.Request) {
    dispatcher := mjq.GetDispatcher()
    testJob1 := &TestJob{}
    // Dispatch dispatches testJob1 to high queue
    _ = dispatcher.Dispatch(testJob1, "high")
    w.WriteHeader(200)
}

func main() {
    // InitializeQueues creates a default queue with 1 worker
    _ = mjq.InitializeQueues(1,
            mjq.AddQueue("high", 4), // AddQueue creates a high queue with 4 workers
            mjq.AddQueue("medium", 2),
    	    mjq.AddQueue("low", 1))

    http.HandleFunc("/job", handler)
    log.Fatal(http.ListenAndServe(":8080", nil))
}

Basic usage example in a console command:

package main
    
import (
    mjq "github.com/jorbriib/multiple-job-queue"
    "math/rand"
)
    
func main() {
    q := mjq.InitializeQueues(0,
      		mjq.AddQueue("high", 5),
      		mjq.AddQueue("medium", 2),
      		mjq.AddQueue("low", 1))
      
    queues := []string{"high", "medium", "low"}
   
    dispatcher := mjq.GetDispatcher()
    for i := 0; i < 100; i++ {
        randomQueue := rand.Intn(len(queues))
        testJob1 := &TestJob{}
        _ = dispatcher.Dispatch(testJob1, queues[randomQueue])
    
    }
    q.WaitUntilFinish()
}  
    	    

FAQs

Package last updated on 02 Sep 2020

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