github.com/iamduo/go-workq

Go client for Workq - https://github.com/iamduo/workq


License
MPL-2.0
Install
go get github.com/iamduo/go-workq

Documentation

go-workq Build Status Coverage Status GitHub Logo

Go client for Workq.

Table of Contents

Connection Management

Connecting

client, err := workq.Connect("localhost:9922")
if err != nil {
  // ...
}

Closing active connection

err := client.Close()
if err != nil {
  // ...
}

Commands Protocol Doc GoDoc

Client Commands

Add

Protocol Doc | Go Doc

Add a background job. The result can be retrieved through the "result" command.

job := &workq.BgJob{
    ID: "6ba7b810-9dad-11d1-80b4-00c04fd430c4",
    Name: "ping",
    TTR: 5000,       // 5 second time-to-run limit
  TTL: 60000,      // Expire after 60 seconds
    Payload: []byte("Ping!"),
    Priority: 10,    // @OPTIONAL Numeric priority, default 0.
    MaxAttempts: 3,  // @OPTIONAL Absolute max num of attempts.
    MaxFails: 1,     // @OPTIONAL Absolute max number of failures.
}
err := client.Add(job)
if err != nil {
    // ...
}

Run

Protocol Doc | Go Doc

Run a job and wait for its result.

job := &workq.FgJob{
    ID: "6ba7b810-9dad-11d1-80b4-00c04fd430c4",
    Name: "ping",
    TTR: 5000,          // 5 second time-to-run limit
    Timeout: 60000, // Wait up to 60 seconds for a worker to pick up.
    Payload: []byte("Ping!"),
    Priority: 10,       // @OPTIONAL Numeric priority, default 0.
}
result, err := client.Run(job)
if err != nil {
  // ...
}

fmt.Printf("Success: %t, Result: %s", result.Success, result.Result)

Schedule

Protocol Doc | Go Doc

Schedule a job at a UTC time. The result can be retrieved through the "result" command.

job := &workq.ScheduledJob{
    ID: "6ba7b810-9dad-11d1-80b4-00c04fd430c4",
    Name: "ping",
    Time:    "2016-12-01T00:00:00Z", // Start job at this UTC time.
    TTL: 60000,                      // Expire after 60 seconds
    TTR: 5000,                       // 5 second time-to-run limit
    Payload: []byte("Ping!"),
    Priority: 10,                    // @OPTIONAL Numeric priority, default 0.
  MaxAttempts: 3,                  // @OPTIONAL Absolute max num of attempts.
  MaxFails: 1,                     // @OPTIONAL Absolute max number of failures.
}
err := client.Schedule(job)
if err != nil {
    // ...
}

Result

Protocol Doc | Go Doc

Get a job result previously executed by Run or Schedule commands.

// Get a job result, waiting up to 60 seconds if the job is still executing.
result, err := client.Result("6ba7b810-9dad-11d1-80b4-00c04fd430c4", 60000)
if err != nil {
    // ...
}

fmt.Printf("Success: %t, Result: %s", result.Success, result.Result)

Worker Commands

Lease

Protocol Doc | Go Doc

Lease a job within a set of one or more names with a wait-timeout (milliseconds).

// Lease the first available job in "ping1", "ping2", "ping3"
// waiting up to 60 seconds.
job, err := client.Lease([]string{"ping1", "ping2", "ping3"}, 60000)
if err != nil {
    // ...
}

fmt.Printf("Leased Job: ID: %s, Name: %s, Payload: %s", job.ID, job.Name, job.Payload)

Complete

Protocol Doc | Go Doc

Mark a job successfully completed with a result.

err := client.Complete("6ba7b810-9dad-11d1-80b4-00c04fd430c4", []byte("Pong!"))
if err != nil {
    // ...
}

Fail

Protocol Doc | Go Doc

Mark a job failed with a result.

err := client.Fail("6ba7b810-9dad-11d1-80b4-00c04fd430c4", []byte("Failed-Pong!"))
if err != nil {
    // ...
}

Adminstrative Commands

Delete

Protocol Doc | Go Doc

err := client.Delete("6ba7b810-9dad-11d1-80b4-00c04fd430c4")
if err != nil {
    // ...
}

Inspect

Protocol Doc

Inspect commands not yet supported yet.