Socket
Socket
Sign inDemoInstall

github.com/p-weisk/gojobqueue

Package Overview
Dependencies
0
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/p-weisk/gojobqueue

Jobs consist of one function that will be executed, and one function that will be called when the first function returns an error, e.g. in order to roll back changes or clean up. First, create a new Queue with a buffer size using the make function. If you do not use a buffer, Adding Jobs will block until the Queue is empty, rendering it rather useless. You can Add jobs to it at any time using AddJob. Whenever you are ready to start executing Jobs, call StartWorking. You can still add jobs afterwards. When you're done with the Queue, you can call Close on it. This will close the underlying channel.


Version published

Readme

Source

Go Job Queue

A Job Queue that will serially process Jobs in the order they were pushed into the queue.

Usage

  • First, create a new Queue with a buffer size using the make function. If you do not use a buffer, Adding Jobs will block until the Queue is empty, rendering it rather useless.
  • You can Add jobs to it at any time using AddJob.
  • Whenever you are ready to start executing Jobs, call StartWorking. You can still add jobs afterwards.
  • When you're done with the Queue, you can call Close on it. This will close the underlying channel.

Exported functions and types

  • type Queue chan job Can be created like a channel, using make with a buffer size: q := make(Queue, 20) // q is a Queue that can hold a maximum of 20 pending jobs at a time.

  • func (q Queue) AddJob(transact func() error, rollback func(error)) (err error) Adds a Job to the Queue it is called on. Takes two arguments: transact func() error // The function that should contain a Job's logic. rollback func(error) // The function will only be called if transact() returns an error, with this error as an argument. Can be used for rolling back changes, doing cleanups, error logging etc. Returns an error if the Queue is already closed (so unlike channels, it will not panic).

  • func (q Queue) Close() Closes the underlying channel.

  • func (q Queue) StartWorking() Starts executing the jobs already in the Queue, and any new Jobs you add to it.

FAQs

Last updated on 16 Dec 2018

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc