Go client for Workq.
Table of Contents
client, err := workq.Connect("localhost:9922")
if err != nil {
// ...
}
err := client.Close()
if err != nil {
// ...
}
Add a background job. The result can be retrieved through the "result" command.
job := &workq.BgJob{
ID: "61a444a0-6128-41c0-8078-cc757d3bd2d8",
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 a job and wait for its result.
job := &workq.FgJob{
ID: "61a444a0-6128-41c0-8078-cc757d3bd2d8",
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 a job at a UTC time. The result can be retrieved through the "result" command.
job := &workq.ScheduledJob{
ID: "61a444a0-6128-41c0-8078-cc757d3bd2d8",
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 {
// ...
}
Get a job result previously executed by Add or Schedule commands.
// Get a job result, waiting up to 60 seconds if the job is still executing.
result, err := client.Result("61a444a0-6128-41c0-8078-cc757d3bd2d8", 60000)
if err != nil {
// ...
}
fmt.Printf("Success: %t, Result: %s", result.Success, result.Result)
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)
Mark a job successfully completed with a result.
err := client.Complete("61a444a0-6128-41c0-8078-cc757d3bd2d8", []byte("Pong!"))
if err != nil {
// ...
}
Mark a job failed with a result.
err := client.Fail("61a444a0-6128-41c0-8078-cc757d3bd2d8", []byte("Failed-Pong!"))
if err != nil {
// ...
}
err := client.Delete("61a444a0-6128-41c0-8078-cc757d3bd2d8")
if err != nil {
// ...
}
Inspect commands not yet supported yet.