-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add optional retry_for argument for task queue (#731)
The `retry_for` argument can be used to provide a list of exceptions. If any of those exceptions are encountered, the task will be retried. It can be used like this: ```python from beta9 import task_queue @task_queue(retries=2, retry_for=[AttributeError]) def hello(): import random import time time.sleep(2) raise AttributeError("This is a test exception") ``` The resulting output will look something like this: ```bash Starting task worker[0] Worker[0] ready Running task <8b96b5c9-3614-4121-aaec-f0b08cc4e108> Retrying task <8b96b5c9-3614-4121-aaec-f0b08cc4e108> after AttributeError exception Running task <8b96b5c9-3614-4121-aaec-f0b08cc4e108> Retrying task <8b96b5c9-3614-4121-aaec-f0b08cc4e108> after AttributeError exception Running task <8b96b5c9-3614-4121-aaec-f0b08cc4e108> Retry limit of 2 exceeded for task <8b96b5c9-3614-4121-aaec-f0b08cc4e108> ```
- Loading branch information
1 parent
fcd4e22
commit 03539fa
Showing
15 changed files
with
263 additions
and
148 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package taskqueue | ||
|
||
import "fmt" | ||
|
||
// Redis keys | ||
var ( | ||
taskQueueList string = "taskqueue:%s:%s" | ||
taskQueueServeLock string = "taskqueue:%s:%s:serve_lock" | ||
taskQueueInstanceLock string = "taskqueue:%s:%s:instance_lock" | ||
taskQueueTaskDuration string = "taskqueue:%s:%s:task_duration" | ||
taskQueueAverageTaskDuration string = "taskqueue:%s:%s:avg_task_duration" | ||
taskQueueTaskHeartbeat string = "taskqueue:%s:%s:task:heartbeat:%s" | ||
taskQueueProcessingLock string = "taskqueue:%s:%s:processing_lock:%s" | ||
taskQueueKeepWarmLock string = "taskqueue:%s:%s:keep_warm_lock:%s" | ||
taskQueueTaskRunningLock string = "taskqueue:%s:%s:task_running:%s:%s" | ||
) | ||
|
||
var Keys = &keys{} | ||
|
||
type keys struct{} | ||
|
||
func (k *keys) taskQueueInstanceLock(workspaceName, stubId string) string { | ||
return fmt.Sprintf(taskQueueInstanceLock, workspaceName, stubId) | ||
} | ||
|
||
func (k *keys) taskQueueServeLock(workspaceName, stubId string) string { | ||
return fmt.Sprintf(taskQueueServeLock, workspaceName, stubId) | ||
} | ||
|
||
func (k *keys) taskQueueList(workspaceName, stubId string) string { | ||
return fmt.Sprintf(taskQueueList, workspaceName, stubId) | ||
} | ||
|
||
func (k *keys) taskQueueTaskHeartbeat(workspaceName, stubId, taskId string) string { | ||
return fmt.Sprintf(taskQueueTaskHeartbeat, workspaceName, stubId, taskId) | ||
} | ||
|
||
func (k *keys) taskQueueTaskDuration(workspaceName, stubId string) string { | ||
return fmt.Sprintf(taskQueueTaskDuration, workspaceName, stubId) | ||
} | ||
|
||
func (k *keys) taskQueueAverageTaskDuration(workspaceName, stubId string) string { | ||
return fmt.Sprintf(taskQueueAverageTaskDuration, workspaceName, stubId) | ||
} | ||
|
||
func (k *keys) taskQueueTaskRunningLock(workspaceName, stubId, containerId, taskId string) string { | ||
return fmt.Sprintf(taskQueueTaskRunningLock, workspaceName, stubId, containerId, taskId) | ||
} | ||
|
||
func (k *keys) taskQueueProcessingLock(workspaceName, stubId, containerId string) string { | ||
return fmt.Sprintf(taskQueueProcessingLock, workspaceName, stubId, containerId) | ||
} | ||
|
||
func (k *keys) taskQueueKeepWarmLock(workspaceName, stubId, containerId string) string { | ||
return fmt.Sprintf(taskQueueKeepWarmLock, workspaceName, stubId, containerId) | ||
} |
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
Oops, something went wrong.