Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
github.imxd.top/jorbriib/multiple-job-queue
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.
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.
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
Unknown package
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.