Context

Many developers start with Rails and as the application grows they start writing code in other languages like Golang. Generally Sidekiq is used to for background jobs Rails. Why not use Sidekiq for Golang!

Open Source Library

Sidekiq compatible background workers in  golang.

Run the following command.

go get github.com/jrallison/go-workers

Sample Code

AddJob method provides a mechanism to queue a new job in Sidekiq queue.

package helpers

import (
  "time"
  "github.com/go-redis/redis/v8"
  "github.com/jrallison/go-workers"
)

func AddJob(queue string, at time.Time, args ...interface{}) string {
  ts := float64(at.UTC().Unix())
  jid, _ := workers.EnqueueWithOptions(queue, "Add", args, workers.EnqueueOptions{Retry: true, RetryCount: 4, At: ts})
  return jid 
}

#sidekiq #workers #rails #golang

Golang & Sidekiq
2.80 GEEK