-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from ripienaar/31
(#31) detect stale active states
- Loading branch information
Showing
7 changed files
with
90 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,14 +21,40 @@ func panicIfErr(err error) { | |
} | ||
} | ||
|
||
func ExampleClient_LoadTaskByID() { | ||
client, err := NewClient(NatsContext("WQ")) | ||
func ExampleClient_producer() { | ||
queue := &Queue{ | ||
Name: "P100", | ||
MaxRunTime: 60 * time.Minute, | ||
MaxConcurrent: 20, | ||
MaxTries: 100, | ||
} | ||
|
||
email := newEmail("[email protected]", "Test Subject", "Test Body") | ||
|
||
// Creates a new task that has a deadline for processing 1 hour from now | ||
task, err := NewTask("email:send", email, TaskDeadline(time.Now().Add(time.Hour))) | ||
panicIfErr(err) | ||
|
||
task, err := client.LoadTaskByID("24ErgVol4ZjpoQ8FAima9R2jEHB") | ||
// Uses the NATS CLI context WQ for connection details, will create the queue if | ||
// it does not already exist | ||
client, err := NewClient(NatsContext("WQ"), WorkQueue(queue)) | ||
panicIfErr(err) | ||
|
||
fmt.Printf("Loaded task %s in state %s", task.ID, task.State) | ||
// Adds the task to the queue called P100 | ||
err = client.EnqueueTask(context.Background(), task) | ||
panicIfErr(err) | ||
} | ||
|
||
func ExampleNewTask_with_deadline() { | ||
email := newEmail("[email protected]", "Test Subject", "Test Body") | ||
|
||
// Creates a new task that has a deadline for processing 1 hour from now | ||
task, err := NewTask("email:send", email, TaskDeadline(time.Now().Add(time.Hour))) | ||
if err != nil { | ||
panic(fmt.Sprintf("Could not create task: %v", err)) | ||
} | ||
|
||
fmt.Printf("Task ID: %s\n", task.ID) | ||
} | ||
|
||
func ExampleClient_consumer() { | ||
|
@@ -41,7 +67,7 @@ func ExampleClient_consumer() { | |
|
||
// Uses the NATS CLI context WQ for connection details, will create the queue if | ||
// it does not already exist | ||
client, err := NewClient(NatsContext("WQ"), WorkQueue(queue)) | ||
client, err := NewClient(NatsContext("WQ"), WorkQueue(queue), RetryBackoffPolicy(RetryLinearOneHour)) | ||
panicIfErr(err) | ||
|
||
router := NewTaskRouter() | ||
|
@@ -60,38 +86,12 @@ func ExampleClient_consumer() { | |
panicIfErr(err) | ||
} | ||
|
||
func ExampleClient_producer() { | ||
queue := &Queue{ | ||
Name: "P100", | ||
MaxRunTime: 60 * time.Minute, | ||
MaxConcurrent: 20, | ||
MaxTries: 100, | ||
} | ||
|
||
email := newEmail("[email protected]", "Test Subject", "Test Body") | ||
|
||
// Creates a new task that has a deadline for processing 1 hour from now | ||
task, err := NewTask("email:send", email, TaskDeadline(time.Now().Add(time.Hour))) | ||
panicIfErr(err) | ||
|
||
// Uses the NATS CLI context WQ for connection details, will create the queue if | ||
// it does not already exist | ||
client, err := NewClient(NatsContext("WQ"), WorkQueue(queue)) | ||
func ExampleClient_LoadTaskByID() { | ||
client, err := NewClient(NatsContext("WQ")) | ||
panicIfErr(err) | ||
|
||
// Adds the task to the queue called P100 | ||
err = client.EnqueueTask(context.Background(), task) | ||
task, err := client.LoadTaskByID("24ErgVol4ZjpoQ8FAima9R2jEHB") | ||
panicIfErr(err) | ||
} | ||
|
||
func ExampleNewTask_with_deadline() { | ||
email := newEmail("[email protected]", "Test Subject", "Test Body") | ||
|
||
// Creates a new task that has a deadline for processing 1 hour from now | ||
task, err := NewTask("email:send", email, TaskDeadline(time.Now().Add(time.Hour))) | ||
if err != nil { | ||
panic(fmt.Sprintf("Could not create task: %v", err)) | ||
} | ||
|
||
fmt.Printf("Task ID: %s\n", task.ID) | ||
fmt.Printf("Loaded task %s in state %s", task.ID, task.State) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters