mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-02 12:22:18 +00:00
Goes from 135 MB binary with 1153 files importing go.temporal.io and 224
importing google.golang.org/grpc to a 10 MB native binary with ZERO of
either.
Deleted:
- tasks/, tasktests/, service/, chasm/, client/, api/, proto/, tools/
- cmd/tools/, components/, docker/
- schema/{cassandra,elasticsearch,mysql,postgresql,sqlite}/
- 40 tainted common/ subdirs + 7 top-level common files
- tests/testutils (no longer referenced after surviving deps drop common)
New cmd/tasksd (~100 lines) boots tasks.Embed (zap.Node) + http.Server.
New pkg/tasks/embed.go registers ZAP handlers for the SDK opcode surface
(0x0060-0x00A5). Workflow handlers return a 501 "not yet implemented"
envelope; native engine lands behind this contract.
Build: go build ./cmd/tasksd → 10 MB
Vet: go vet ./... → clean
Boot: tasksd --zap-port 9999 --http :7243
Probes: /healthz, /v1/tasks/health → 200
UI: /_/tasks/, / → 200 (embedded Vite bundle)
ZAP: _tasks._tcp on :9999 (mDNS disabled; direct connect)
go.mod: tidy. No go.temporal.io. No google.golang.org/grpc.
78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
package queues
|
|
|
|
import (
|
|
enumsspb "go.temporal.io/server/api/enums/v1"
|
|
"go.temporal.io/server/common/namespace"
|
|
"go.temporal.io/server/common/tasks"
|
|
)
|
|
|
|
type (
|
|
// PriorityAssigner assigns priority to task executables
|
|
PriorityAssigner interface {
|
|
Assign(Executable) tasks.Priority
|
|
}
|
|
|
|
priorityAssignerImpl struct {
|
|
currentClusterName string
|
|
nsRegistry namespace.Registry
|
|
}
|
|
|
|
staticPriorityAssigner struct {
|
|
priority tasks.Priority
|
|
}
|
|
)
|
|
|
|
func NewPriorityAssigner(nsRegistry namespace.Registry, currentClusterName string) PriorityAssigner {
|
|
return &priorityAssignerImpl{
|
|
nsRegistry: nsRegistry,
|
|
currentClusterName: currentClusterName,
|
|
}
|
|
}
|
|
|
|
func (a *priorityAssignerImpl) Assign(executable Executable) tasks.Priority {
|
|
ns, err := a.nsRegistry.GetNamespaceByID(namespace.ID(executable.GetNamespaceID()))
|
|
if ns != nil && err == nil {
|
|
// Use lowest priority level for standby task processing
|
|
if !ns.ActiveInCluster(a.currentClusterName) {
|
|
return tasks.PriorityPreemptable
|
|
}
|
|
}
|
|
|
|
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,
|
|
enumsspb.TASK_TYPE_WORKER_COMMANDS:
|
|
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
|
|
}
|