File: task.go

package info (click to toggle)
aptly 1.5.0%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 48,840 kB
  • sloc: python: 7,966; sh: 798; makefile: 81
file content (65 lines) | stat: -rw-r--r-- 1,279 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package task

import (
	"sync/atomic"

	"github.com/aptly-dev/aptly/aptly"
)

// State task is in
type State int

// Detail represents custom task details
type Detail struct {
	atomic.Value
}

// PublishDetail represents publish task details
type PublishDetail struct {
	*Detail
	TotalNumberOfPackages     int64
	RemainingNumberOfPackages int64
}

type ProcessReturnValue struct {
	Code  int
	Value interface{}
}

// Process is a function implementing the actual task logic
type Process func(out aptly.Progress, detail *Detail) (*ProcessReturnValue, 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
	processReturnValue *ProcessReturnValue
	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
}