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
Created
April 28, 2015 17:53
-
-
Save nathany/17d41dad27861978478a to your computer and use it in GitHub Desktop.
Go / Ruby bridge with Sidekiq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sidekiq' | |
Sidekiq::configure_client do |config| | |
config.redis = { namespace: "goworkers", size: 1 } | |
end | |
Sidekiq::Client.push "queue" => "goqueue", "class" => "MyGoWorker", "args" => ["pong"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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