gokiq

package module
Version: v0.0.0-...-23d51ee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2021 License: MIT Imports: 6 Imported by: 0

README

Gokiq Build Status

Gokiq is a small library to easily enqueue Sidekiq jobs from Go.

Usage

import (
  "github.com/duosrx/gokiq"
  "github.com/gomodule/redigo/redis"
  "time"
)

// Create a Redis Pool first
var pool = &redis.Pool{
	MaxIdle:     3,
	IdleTimeout: 240 * time.Second,
	Dial: func() (redis.Conn, error) {
		return redis.Dial("tcp", ":6379")
	},
}

job := NewJob("HardWorker", "default", []string{"foo", "bar"})

// Enqueue immediately...
job.Enqueue(pool)

// ... or enqueue in the future
now := time.Now()
job.EnqueueAt(now, pool)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	JID        string        `json:"jid"`
	Retry      int           `json:"retry"`
	Queue      string        `json:"queue"`
	Class      string        `json:"class"`
	Args       []interface{} `json:"args"`
	EnqueuedAt int64         `json:"enqueued_at"`
}

Job holds all the information about the job to be enqueued.

func NewJob

func NewJob(class, queue string, args []interface{}, retry int) *Job

NewJob initialize a new job given a class, queue and arguments.

func (*Job) Enqueue

func (job *Job) Enqueue(pool *redis.Pool) error

Enqueue inserts the job into the Sidekiq queue instantly.

func (*Job) EnqueueAt

func (job *Job) EnqueueAt(time time.Time, pool *redis.Pool) error

EnqueueAt insert the job into the Sidekiq scheduled queue at the given time.

func (*Job) EnqueueIn

func (job *Job) EnqueueIn(duration time.Duration, pool *redis.Pool) error

EnqueueIn insert the job into the queue after the given duration.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL