Skip to content

Instantly share code, notes, and snippets.

@raliste
Created October 13, 2013 01:50
Show Gist options
  • Save raliste/6957127 to your computer and use it in GitHub Desktop.
Save raliste/6957127 to your computer and use it in GitHub Desktop.
Super easy and scalable async queues with Python and Golang. And see nice stats by doing `gem install resque` and then `resque-web`. You might need to add your goworker queue into redis to make it show up in resque-web.
import redis
RESQUE_QUEUE = 'resque:queue:%s'
def test(n=0):
r = redis.Redis()
r.rpush(RESQUE_QUEUE % 'notifications', '{"class":"EmailNotification","args":["hi","there %s"]}' % n)
if __name__ == '__main__':
for i in xrange(100):
test(i)
package main
import (
"log"
"github.com/benmanns/goworker"
)
func init() {
goworker.Register("EmailNotification", emailNotification)
}
func emailNotification(queue string, args ...interface{}) error {
log.Println("emailNotification")
log.Println("args:", args)
return nil
}
func main() {
log.Println("Running notifications workers...")
if err := goworker.Work(); err != nil {
log.Fatal("Error:", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment