Socket
Book a DemoInstallSign in
Socket

github.com/256dpi/mgojq

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/256dpi/mgojq

v0.2.0
Source
Go
Version published
Created
Source

mgojq

Build Status Coverage Status GoDoc Release Go Report Card

A wrapper for mgo that turns MongoDB into a job queue.

Example

// get jobs collection
coll := Wrap(db.C("jobs"))

// ensure indexes
err := coll.EnsureIndexes(7 * 24 * time.Hour)
if err != nil {
    panic(err)
}

// create a worker pool
pool := NewPool(1, 100*time.Millisecond, 1*time.Hour)

// register worker
pool.Register("Adder", func(c *Collection, j *Job, q <-chan struct{}) error {
    r := j.Params["a"].(int) + j.Params["b"].(int)
    c.Complete(j.ID, bson.M{"r": r})
    return nil
})

// start pool
pool.Start(coll)
defer pool.Close()

// add job
id, err := coll.Enqueue("Adder", bson.M{"a": 10, "b": 5}, 0)
if err != nil {
    panic(err)
}

// wait some time
time.Sleep(200 * time.Millisecond)

// get job
job, err := coll.Fetch(id)
if err != nil {
    panic(err)
}

fmt.Printf("%s: %d\n", job.Status, job.Result["r"].(int))

// Output:
// completed: 15

FAQs

Package last updated on 08 Feb 2019

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.