gearman

package module
v2.0.2+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2015 License: Apache-2.0 Imports: 11 Imported by: 0

README

gearman

-- import "gopkg.in/Clever/gearman.v2"

Package gearman provides a thread-safe Gearman client

Example

Here's an example program that submits a job to Gearman and listens for events from that job:

package main

import(
	"gopkg.in/Clever/gearman.v2"
	"ioutil"
)

func main() {
	client, err := gearman.NewClient("tcp4", "localhost:4730")
	if err != nil {
		panic(err)
	}

	j, err := client.Submit("reverse", []byte("hello world!"), nil, nil)
	if err != nil {
		panic(err)
	}
	state := j.Run()
	println(state) // job.Completed
	data, err := ioutil.ReadAll(j.Data())
	if err != nil {
		panic(err)
	}
	println(data) // !dlrow olleh
}

Usage

type Client
type Client struct {
}

Client is a Gearman client

func NewClient
func NewClient(network, addr string) (*Client, error)

NewClient returns a new Gearman client pointing at the specified server

func (*Client) Close
func (c *Client) Close() error

Close terminates the connection to the server

func (*Client) Submit
func (c *Client) Submit(fn string, payload []byte, data, warnings io.WriteCloser) (*job.Job, error)

Submit sends a new job to the server with the specified function and payload. You must provide two WriteClosers for data and warnings to be written to.

func (*Client) SubmitBackground
func (c *Client) SubmitBackground(fn string, payload []byte) error

SubmitBackground submits a background job. There is no access to data, warnings, or completion state.

Documentation

Overview

Package gearman provides a thread-safe Gearman client

Example

Here's an example program that submits a job to Gearman and listens for events from that job:

package main

import(
	"gopkg.in/Clever/gearman.v2"
	"ioutil"
)

func main() {
	client, err := gearman.NewClient("tcp4", "localhost:4730")
	if err != nil {
		panic(err)
	}

	j, err := client.Submit("reverse", []byte("hello world!"), nil, nil)
	if err != nil {
		panic(err)
	}
	state := j.Run()
	println(state) // job.Completed
	data, err := ioutil.ReadAll(j.Data())
	if err != nil {
		panic(err)
	}
	println(data) // !dlrow olleh
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a Gearman client

func NewClient

func NewClient(network, addr string) (*Client, error)

NewClient returns a new Gearman client pointing at the specified server

func (*Client) Close

func (c *Client) Close() error

Close terminates the connection to the server

func (*Client) Submit

func (c *Client) Submit(fn string, payload []byte, data, warnings io.WriteCloser) (*job.Job, error)

Submit sends a new job to the server with the specified function and payload. You must provide two WriteClosers for data and warnings to be written to.

func (*Client) SubmitBackground

func (c *Client) SubmitBackground(fn string, payload []byte) error

SubmitBackground submits a background job. There is no access to data, warnings, or completion state.

Directories

Path Synopsis
Package packet provides structures to marshal binary data to and from binary data.
Package packet provides structures to marshal binary data to and from binary data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL