Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Clever/ARCHIVED-baseworker-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Releases

No releases published

Packages

No packages published