Skip to content

Instantly share code, notes, and snippets.

@fsouza
Created January 2, 2013 13:37
Show Gist options
  • Select an option

  • Save fsouza/4434633 to your computer and use it in GitHub Desktop.

Select an option

Save fsouza/4434633 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"encoding/gob"
"github.com/kr/beanstalk"
"fmt"
)
type Message struct {
Action string
Args []string
}
func main() {
buf := new(bytes.Buffer)
m := Message{
Action: "regenerate-apprc",
Args: []string{"myapp"},
}
err := gob.NewEncoder(buf).Encode(m)
if err != nil {
panic(err)
}
c, err := beanstalk.Dial("tcp", "127.0.0.1:11300")
if err != nil {
panic(err)
}
defer c.Close()
id, err := c.Put(buf.Bytes(), 1, 0, 120e9)
if err != nil {
panic(err)
}
fmt.Println(id)
id, body, err := c.Reserve(1e9)
if err != nil {
panic(err)
}
fmt.Println(id)
buf = bytes.NewBuffer(body)
err = gob.NewDecoder(buf).Decode(&m)
if err != nil {
panic(err)
}
fmt.Println(m)
fmt.Println(c.Delete(id))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment