14360: Initial version of dispatch-cloud.
[arvados.git] / lib / dispatchcloud / worker / worker.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package worker
6
7 import (
8         "time"
9 )
10
11 // State indicates whether a worker is available to do work, and (if
12 // not) whether/when it is expected to become ready.
13 type State int
14
15 const (
16         StateUnknown  State = iota // might be running a container already
17         StateBooting               // instance is booting
18         StateRunning               // instance is running
19         StateShutdown              // worker has stopped monitoring the instance
20         StateHold                  // running, but not available to run new containers
21 )
22
23 const (
24         // TODO: configurable
25         maxPingFailTime = 10 * time.Minute
26 )
27
28 var stateString = map[State]string{
29         StateUnknown:  "unknown",
30         StateBooting:  "booting",
31         StateRunning:  "running",
32         StateShutdown: "shutdown",
33         StateHold:     "hold",
34 }
35
36 // String implements fmt.Stringer.
37 func (s State) String() string {
38         return stateString[s]
39 }
40
41 // MarshalText implements encoding.TextMarshaler so a JSON encoding of
42 // map[State]anything uses the state's string representation.
43 func (s State) MarshalText() ([]byte, error) {
44         return []byte(stateString[s]), nil
45 }