mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-02 12:22:18 +00:00
## What changed? Split background task priority to two levels BackgroundLow and BackgroundHigh. Tasks like ActivityTimeout, WorkflowTaskTimeout, WorkflowRunTimeout, WorkflowExecutionTimeout will have BackgroundLow priority. Other tasks like UserTime, TransferWorkflowTask, TransferActivity task etc will have BackgroundHigh priority. System tasks like retention timers will still have the lowest priority level as before. ## Why? This will help the task processor prioritize important tasks like UserTimer and TransferWorkflowTasks when there is rate limiting. Tasks like timeout timers have comparatively lower priority. ## How did you test it? - [ ] built - [ ] run locally and tested manually - [ ] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s) --------- Co-authored-by: Yichao Yang <[email protected]>
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package queues
|
|
|
|
import (
|
|
enumsspb "go.temporal.io/server/api/enums/v1"
|
|
"go.temporal.io/server/common/tasks"
|
|
)
|
|
|
|
type (
|
|
// PriorityAssigner assigns priority to task executables
|
|
PriorityAssigner interface {
|
|
Assign(Executable) tasks.Priority
|
|
}
|
|
|
|
priorityAssignerImpl struct{}
|
|
|
|
staticPriorityAssigner struct {
|
|
priority tasks.Priority
|
|
}
|
|
)
|
|
|
|
func NewPriorityAssigner() PriorityAssigner {
|
|
return &priorityAssignerImpl{}
|
|
}
|
|
|
|
func (a *priorityAssignerImpl) Assign(executable Executable) tasks.Priority {
|
|
taskType := executable.GetType()
|
|
switch taskType {
|
|
case enumsspb.TASK_TYPE_ACTIVITY_TIMEOUT,
|
|
enumsspb.TASK_TYPE_WORKFLOW_TASK_TIMEOUT,
|
|
enumsspb.TASK_TYPE_WORKFLOW_RUN_TIMEOUT,
|
|
enumsspb.TASK_TYPE_WORKFLOW_EXECUTION_TIMEOUT:
|
|
return tasks.PriorityLow
|
|
case enumsspb.TASK_TYPE_DELETE_HISTORY_EVENT,
|
|
enumsspb.TASK_TYPE_TRANSFER_DELETE_EXECUTION,
|
|
enumsspb.TASK_TYPE_VISIBILITY_DELETE_EXECUTION,
|
|
enumsspb.TASK_TYPE_ARCHIVAL_ARCHIVE_EXECUTION,
|
|
enumsspb.TASK_TYPE_UNSPECIFIED:
|
|
// add more task types here if we believe it's ok to delay those tasks
|
|
// and assign them the same priority as throttled tasks
|
|
return tasks.PriorityPreemptable
|
|
}
|
|
|
|
if _, ok := enumsspb.TaskType_name[int32(taskType)]; !ok {
|
|
// low priority for unknown task types
|
|
return tasks.PriorityPreemptable
|
|
}
|
|
|
|
return tasks.PriorityHigh
|
|
}
|
|
|
|
func NewNoopPriorityAssigner() PriorityAssigner {
|
|
return NewStaticPriorityAssigner(tasks.PriorityHigh)
|
|
}
|
|
|
|
func NewStaticPriorityAssigner(priority tasks.Priority) PriorityAssigner {
|
|
return staticPriorityAssigner{priority: priority}
|
|
}
|
|
|
|
func (a staticPriorityAssigner) Assign(_ Executable) tasks.Priority {
|
|
return a.priority
|
|
}
|