baseworker

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2017 License: Apache-2.0 Imports: 9 Imported by: 4

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 {
	sync.Mutex
	// 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.

func (*Worker) Shutdown added in v0.8.0

func (worker *Worker) Shutdown()

Shutdown blocks while waiting for all jobs to finish

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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