baseworker

package module
v0.0.0-...-97a2875 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

README

DEPRECATED

baseworker-go is no longer supported. We suggest you utilize gearcmd instead.

baseworker

-- import "github.com/Clever/baseworker-go"

Package baseworker provides a simple wrapper around a Gearman worker, based on http://godoc.org/github.com/mikespook/gearman-go.

Example

Here's an example program that just listens for "test" jobs and logs the data that it receives:

package main

import(
	"github.com/Clever/baseworker-go"
	"log"
)

func jobFunc(job baseworker.Job) ([]byte, error) {
	log.Printf("Got job with data %s", job.Data())
	return []byte{}, nil
}

func main() {
	worker := baseworker.NewWorker("test", jobFunc)
	defer worker.Close()
	worker.Listen("localhost", "4730")
}

Usage

type Job
type Job gearmanWorker.Job

Job is an alias for http://godoc.org/github.com/mikespook/gearman-go/worker#Job.

type JobFunc
type JobFunc func(Job) ([]byte, error)

JobFunc is a function that takes in a Gearman job and does some work on it.

type SigtermHandler
type SigtermHandler func(*Worker)

SigtermHandler is the definition for the function called after the worker receives a TERM signal.

type Worker
type Worker struct {
}

Worker represents a Gearman worker.

func NewWorker
func NewWorker(name string, fn JobFunc) *Worker

NewWorker creates a new gearman worker with the specified name and job function.

func (*Worker) Close
func (worker *Worker) Close()

Close closes the connection.

func (*Worker) Listen
func (worker *Worker) Listen(host, port string) error

Listen starts listening for jobs on the specified host and port.

Testing

You can run the test cases by typing make test

Documentation

The documentation is automatically generated via godocdown.

You can update it by typing make docs.

They're also viewable online at GoDoc.

Documentation

Overview

Package baseworker provides a simple wrapper around a Gearman worker, based on http://godoc.org/github.com/mikespook/gearman-go.

Example

Here's an example program that just listens for "test" jobs and logs the data that it receives:

package main

import(
	"github.com/Clever/baseworker-go"
	"log"
)

func jobFunc(job baseworker.Job) ([]byte, error) {
	log.Printf("Got job with data %s", job.Data())
	return []byte{}, nil
}

func main() {
	worker := baseworker.NewWorker("test", jobFunc)
	defer worker.Close()
	worker.Listen("localhost", "4730")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JobFunc

type JobFunc func(Job) ([]byte, error)

JobFunc is a function that takes in a Gearman job and does some work on it.

type SigtermHandler

type SigtermHandler func(*Worker)

SigtermHandler is the definition for the function called after the worker receives a TERM signal.

type Worker

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

Worker represents a Gearman worker.

func NewWorker

func NewWorker(name string, fn JobFunc) *Worker

NewWorker creates a new gearman worker with the specified name and job function.

func (*Worker) Close

func (worker *Worker) Close()

Close closes the connection.

func (*Worker) Listen

func (worker *Worker) Listen(host, port string) error

Listen starts listening for jobs on the specified host and port.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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