### Create Simple goworker Worker - Go Source: https://github.com/benmanns/goworker/blob/master/README.md This is a complete example of a basic goworker worker that prints its queue and arguments. It defines a worker function, registers it, and starts the worker process. ```Go package main import ( "fmt" "github.com/benmanns/goworker" ) func myFunc(queue string, args ...interface{}) error { fmt.Printf("From %s, %v\n", queue, args) return nil } func init() { goworker.Register("MyClass", myFunc) } func main() { if err := goworker.Work(); err != nil { fmt.Println("Error:", err) } } ``` -------------------------------- ### Install goworker Package - Shell Source: https://github.com/benmanns/goworker/blob/master/README.md Use the standard Go command to fetch and install the goworker library. ```Shell go get github.com/benmanns/goworker ``` -------------------------------- ### Create goworker Worker with Settings - Go Source: https://github.com/benmanns/goworker/blob/master/README.md Shows how to configure goworker using a WorkerSettings struct before registering workers and starting the process. This allows customizing Redis connection, queues, concurrency, etc. ```Go package main import ( "fmt" "github.com/benmanns/goworker" ) func myFunc(queue string, args ...interface{}) error { fmt.Printf("From %s, %v\n", queue, args) return nil } func init() { settings := goworker.WorkerSettings{ URI: "redis://localhost:6379/", Connections: 100, Queues: []string{"myqueue", "delimited", "queues"}, UseNumber: true, ExitOnComplete: false, Concurrency: 2, Namespace: "resque:", Interval: 5.0, } goworker.SetSettings(settings) goworker.Register("MyClass", myFunc) } func main() { if err := goworker.Work(); err != nil { fmt.Println("Error:", err) } } ``` -------------------------------- ### Enqueue Job using Resque - Ruby Source: https://github.com/benmanns/goworker/blob/master/README.md Example of how to enqueue a job for a worker class using the Ruby Resque library, compatible with goworker. ```Ruby class MyClass @queue = :myqueue end 100.times do Resque.enqueue MyClass, ['hi', 'there'] end ``` -------------------------------- ### Enqueue Job using goworker - Go Source: https://github.com/benmanns/goworker/blob/master/README.md Demonstrates how to programmatically enqueue a job onto a Redis queue using the goworker library itself. ```Go goworker.Enqueue(&goworker.Job{ Queue: "myqueue", Payload: goworker.Payload{ Class: "MyClass", Args: []interface{}{"hi", "there"}, }, }) ``` -------------------------------- ### Create goworker Worker with Closure - Go Source: https://github.com/benmanns/goworker/blob/master/README.md Demonstrates how to use a closure to create worker functions that share resources or maintain state, such as a database connection pool. ```Go package main import ( "fmt" "github.com/benmanns/goworker" ) func newMyFunc(uri string) (func(queue string, args ...interface{}) error) { foo := NewFoo(uri) return func(queue string, args ...interface{}) error { foo.Bar(args) return nil } } func init() { goworker.Register("MyClass", newMyFunc("http://www.example.com/")) } func main() { if err := goworker.Work(); err != nil { fmt.Println("Error:", err) } } ``` -------------------------------- ### Enqueue Job using redis-cli - Shell Source: https://github.com/benmanns/goworker/blob/master/README.md Use the Redis command-line interface to manually push a job payload onto a Resque-compatible queue for testing goworker. ```Shell redis-cli -r 100 RPUSH resque:queue:myqueue '{"class":"MyClass","args":["hi","there"]}' ``` -------------------------------- ### Import goworker Package - Go Source: https://github.com/benmanns/goworker/blob/master/README.md Import the goworker package into your Go project to use its functions and types. ```Go import "github.com/benmanns/goworker" ``` -------------------------------- ### Handle Worker Arguments with Type Assertion - Go Source: https://github.com/benmanns/goworker/blob/master/README.md Illustrates how to safely access and convert arguments passed to a worker function using Go's type assertions, handling potential errors. ```Go // Expecting (int, string, float64) func myFunc(queue, args ...interface{}) error { idNum, ok := args[0].(json.Number) if !ok { return errorInvalidParam } id, err := idNum.Int64() if err != nil { return errorInvalidParam } name, ok := args[1].(string) if !ok { return errorInvalidParam } weightNum, ok := args[2].(json.Number) if !ok { return errorInvalidParam } weight, err := weightNum.Float64() if err != nil { return errorInvalidParam } doSomething(id, name, weight) return nil } ``` -------------------------------- ### Redis Key Format for Failed Job Data Source: https://github.com/benmanns/goworker/blob/master/README.md This snippet shows the format of the Redis key where goworker stores information about a job that was being processed by a worker when the process failed unexpectedly (e.g., via KILL signal). The data stored at this key is a JSON object containing the job's queue, run time, and payload. ```Text resque:worker::-: ``` -------------------------------- ### Define Worker Function Signature - Go Source: https://github.com/benmanns/goworker/blob/master/README.md Worker functions in goworker must match this specific signature, accepting the queue name and a variadic slice of arguments, returning an error. ```Go func(string, ...interface{}) error ``` -------------------------------- ### Register Worker Function - Go Source: https://github.com/benmanns/goworker/blob/master/README.md Register a Go function with goworker, associating it with a specific class name that will be used in job payloads. ```Go goworker.Register("MyClass", myFunc) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.