/ pkg / events.go
events.go
  1  package dogeboxd
  2  
  3  import "time"
  4  
  5  // A Job is created when an Action is recieved by the system.
  6  // Jobs are passed through the Dogeboxd service and result in
  7  // a Change being send to the client via websockets.
  8  type Job struct {
  9  	A       Action
 10  	ID      string
 11  	Err     string
 12  	Success any
 13  	Start   time.Time // set when the job is first created, for calculating duration
 14  	Logger  *actionLogger
 15  	State   *PupState // nilable, check before use!
 16  }
 17  
 18  // A Change can be the result of a Job (same ID) or
 19  // represent an internal system change originating
 20  // from elsewhere.
 21  //
 22  // A Change encodes an 'update' (see below)
 23  // A Change as the result of an Action may carry
 24  // an 'error' to the frontend for the same Job ID
 25  type Change struct {
 26  	ID     string `json:"id"`
 27  	Error  string `json:"error"`
 28  	Type   string `json:"type"`
 29  	Update Update `json:"update"`
 30  }
 31  
 32  // Represents some information about an action underway
 33  type ActionProgress struct {
 34  	ActionID  string        `json:"actionID"`
 35  	PupID     string        `json:pupID`        // optional, only if a pup action
 36  	Progress  int           `json:"progress"`   // 0-100
 37  	Step      string        `json:"step"`       // a unique name for the step we're up to, ie: installing
 38  	Msg       string        `json:"msg"`        // the message line
 39  	Error     bool          `json:"error"`      // if this represents an error or not
 40  	StepTaken time.Duration `json:"step_taken"` // time taken from previous step
 41  }
 42  
 43  /* Actions are passed to the dogeboxd service via its
 44   * AddAction method, and represent tasks that need to
 45   * be done such as installing a package, starting or
 46   * stopping a service etc.
 47   */
 48  type Action any
 49  
 50  // Install a pup on the system
 51  type InstallPup struct {
 52  	PupName      string
 53  	PupVersion   string
 54  	SourceId     string
 55  	SessionToken string
 56  }
 57  
 58  // Uninstalling a pup will remove container
 59  // configuration, but keep storage.
 60  type UninstallPup struct {
 61  	PupID string
 62  }
 63  
 64  // Purging a pup will remove the container storage.
 65  type PurgePup struct {
 66  	PupID string
 67  }
 68  
 69  // Enable a previously disabled pup
 70  type EnablePup struct {
 71  	PupID string
 72  }
 73  
 74  // Disable (stop) a running pup
 75  type DisablePup struct {
 76  	PupID string
 77  }
 78  
 79  // Updates the config values in a PUPState object
 80  type UpdatePupConfig struct {
 81  	PupID   string
 82  	Payload map[string]string
 83  }
 84  
 85  // Updates the providers of dependant interfaces for this pup
 86  type UpdatePupProviders struct {
 87  	PupID   string
 88  	Payload map[string]string
 89  }
 90  
 91  // Updates hooks for this pup
 92  type UpdatePupHooks struct {
 93  	PupID   string
 94  	Payload []PupHook
 95  }
 96  
 97  // updates the custom metrics for a pup
 98  type UpdateMetrics struct {
 99  	PupID   string
100  	Payload map[string]PupMetric
101  }
102  
103  type PupMetric struct {
104  	Value any `json:"value"`
105  }
106  
107  type UpdatePendingSystemNetwork struct {
108  	Network SelectedNetwork
109  }
110  
111  type (
112  	EnableSSH  struct{}
113  	DisableSSH struct{}
114  )
115  
116  type AddSSHKey struct {
117  	Key string
118  }
119  
120  type RemoveSSHKey struct {
121  	ID string
122  }
123  
124  /* Updates are responses to Actions or simply
125  * internal state changes that the frontend needs,
126  * these are wrapped in a 'change' and sent via
127  * websocket to the client.
128  *
129  * Updates need to be json-marshalable types
130   */
131  type Update any
132  
133  // StatsUpdate represents one or more PupStats updates
134  type StatsUpdate struct {
135  	Stats []PupStats `json:"stats"`
136  }