Add task api and resource locking ability

This commit is contained in:
Oliver Sauder
2017-05-22 11:51:35 +02:00
committed by Lorenzo Bolla
parent e63d74dff2
commit 6ab5e60833
24 changed files with 1519 additions and 620 deletions
+50
View File
@@ -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
}