Ruby Background Jobs with GoWorker

About me

Julio López


Background Jobs

A computer process that runs "behind the scenes" (in the background) and without user intervention


Redis is an open source NOSQL key-value data store with multiple datatypes: stringshasheslistssets,sorted setsbitmaps, etc.


Redis-backed library for creating background jobs, placing those jobs on multiple queues, and processing them later.

Created and used by github


A go based background worker for Resque. 

  • A simple binarie
  • Polls Resque queues
  • Dispatches jobs via go routines
  • Use Ruby to push the jobs and the concurrency of Go to minimize job latency

How fast is it?

For simple dequeuing, deserialization, execution, and updating stats, goworker is 80x faster than Resque and 23x faster than Sidekiq.

Additionally, goworker only used 7MB of memory, while Sidekiq used 74MB and Resque 62MB.


Write a Go worker


package main

import (

func main() {
  if err := goworker.Work(); err != nil {
    fmt.Println("Error:", err)

Write your worker func

func init() {
  goworker.Register("Hello", helloWorker)

func helloWorker(queue string, args ...interface{}) error {
  fmt.Printf("Hello %v", args[0])
  return nil

Build and Run it

$ go build

$ ./worker -queues=hello

Build your go file to a binary

Start the Redis Server

$ redis-server

Run your go worker

Enqueue the job

require 'resque'

class Hello

Resque.push('hello', 'class' => 'Hello', 'args' => ["World"])


Or you can test it using the redis command line:

redis-cli -r 1 RPUSH resque:queue:hello '{"class":"Hello","args":["World"]}'


Sending mails with GoWorker


Background Jobs con Go

By Julio López Montalvo

Background Jobs con Go

  • 1,341
Loading comments...

More from Julio López Montalvo