Skip to content

Instantly share code, notes, and snippets.

@nathany nathany/README.md
Created Apr 28, 2015

Embed
What would you like to do?
Go / Ruby bridge with Sidekiq
brew install redis
gem install sidekiq
go get -u github.com/jrallison/go-workers

redis-server /usr/local/etc/redis.conf
sidekiq -r ./sks.rb
go run sk.go
ruby skc.rb
package main
import (
"log"
"github.com/jrallison/go-workers"
)
func myJob(message *workers.Msg) {
log.Println("running task", message)
log.Println(message.OriginalJson())
}
func main() {
workers.Configure(map[string]string{
// location of redis instance
"server": "localhost:6379",
// instance of the database
"database": "0",
// number of connections to keep open with redis
"pool": "30",
// unique process id for this instance of workers (for proper recovery of in progress jobs on crash)
"process": "1",
// namespace
"namespace": "goworkers",
// poll_interval: "15"
// password: ""
})
// pull messages from "goqueue" with concurrency of 10
workers.Process("goqueue", myJob, 10)
// send a message
workers.Enqueue("rubyqueue", "MyRubyWorker", []string{"ping"})
// Blocks until process is told to exit via unix signal
workers.Run()
}
require 'sidekiq'
Sidekiq::configure_client do |config|
config.redis = { namespace: "goworkers", size: 1 }
end
Sidekiq::Client.push "queue" => "goqueue", "class" => "MyGoWorker", "args" => ["pong"]
# sidekiq -r ./sks.rb
require 'sidekiq'
Sidekiq::configure_server do |config|
config.redis = { namespace: "goworkers" }
end
Sidekiq.options[:queues] = ["rubyqueue"]
class MyRubyWorker
include Sidekiq::Worker
def perform(str)
puts "Hello from Sidekiq: #{str}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.