mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-06 05:30:57 +00:00
Add task api and resource locking ability
This commit is contained in:
committed by
Lorenzo Bolla
parent
e63d74dff2
commit
6ab5e60833
@@ -0,0 +1,50 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
// State task is in
|
||||
type State int
|
||||
|
||||
// Detail represents custom task details
|
||||
type Detail struct {
|
||||
atomic.Value
|
||||
}
|
||||
|
||||
// Process is a function implementing the actual task logic
|
||||
type Process func(out *Output, detail *Detail) error
|
||||
|
||||
const (
|
||||
// IDLE when task is waiting
|
||||
IDLE State = iota
|
||||
// RUNNING when task is running
|
||||
RUNNING
|
||||
// SUCCEEDED when task is successfully finished
|
||||
SUCCEEDED
|
||||
// FAILED when task failed
|
||||
FAILED
|
||||
)
|
||||
|
||||
// Task represents as task in a queue encapsulates process code
|
||||
type Task struct {
|
||||
output *Output
|
||||
detail *Detail
|
||||
process Process
|
||||
Name string
|
||||
ID int
|
||||
State State
|
||||
}
|
||||
|
||||
// NewTask creates new task
|
||||
func NewTask(process Process, name string, ID int) *Task {
|
||||
task := &Task{
|
||||
output: NewOutput(),
|
||||
detail: &Detail{},
|
||||
process: process,
|
||||
Name: name,
|
||||
ID: ID,
|
||||
State: IDLE,
|
||||
}
|
||||
return task
|
||||
}
|
||||
Reference in New Issue
Block a user