data

package
v0.0.0-...-fd84699 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package data -> this package is responsible for the data layer

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateCapsuleProcessRecord

func CreateCapsuleProcessRecord(process CapsuleProcess) (string, int)

CreateCapsuleProcessRecord creates a new CapsuleProcess record and returns its key.

process: a CapsuleProcess struct containing information about the process. string: the key of the newly created CapsuleProcess record.

func DeleteCapsuleProcessRecord

func DeleteCapsuleProcessRecord(key string) string

DeleteCapsuleProcessRecord deletes a process record from the runningCapsules map given a key.

key: a string representing the key to delete from the map. returns: a string representing the deleted key.

func GetJSONCapsuleProcesses

func GetJSONCapsuleProcesses() ([]byte, error)

GetJSONCapsuleProcesses retrieves a JSON-encoded list of running capsule processes.

This function takes no parameters and returns a slice of bytes and an error.

func GetStatusLabel

func GetStatusLabel(status Status) string

GetStatusLabel returns the status label for a given status.

status: a Status type representing the current status of the process. Returns a string representing the label for the current status.

func SaveCapsuleProcessRecords

func SaveCapsuleProcessRecords() error

SaveCapsuleProcessRecords saves the runningCapsules map to a json file at the specified storage location. It returns an error if one occurs.

Return: error

func SearchLastIndexOfProcessRecord

func SearchLastIndexOfProcessRecord(functionName, functionRevision string) int

SearchLastIndexOfProcessRecord returns the last order number of the processes with the given function name and revision.

functionName: the name of the function to search for. functionRevision: the revision of the function to search for. int: the last order number of the processes found.

func SetCapsuleProcessRecord

func SetCapsuleProcessRecord(process CapsuleProcess) string

SetCapsuleProcessRecord stores a CapsuleProcess for a given key in the runningCapsules map.

key: a string representing the key to store the CapsuleProcess. process: a CapsuleProcess to be stored in the runningCapsules map.

Types

type CapsuleProcess

type CapsuleProcess struct {
	Index                  int       `json:"index"`
	FunctionName           string    `json:"functionName"`
	FunctionRevision       string    `json:"functionRevision"`
	FormerFunctionRevision string    `json:"formerFunctionRevision"`
	HTTPPort               string    `json:"httpPort"`
	Description            string    `json:"description"`
	CurrentStatus          Status    `json:"currentStatus"`
	StatusDescription      string    `json:"statusDescription"`
	CreatedAt              time.Time `json:"createdAt"` // record the time the event was requested
	StartedAt              time.Time `json:"startedAt"`
	FinishedAt             time.Time `json:"finishedAt"`
	CancelledAt            time.Time `json:"cancelledAt"`
	FailedAt               time.Time `json:"failedAt"`
	CheckedAt              time.Time `json:"checkedAt"`
	Pid                    int       `json:"pid"`
	Path                   string    `json:"path"`
	Args                   []string  `json:"args"`
	Env                    []string  `json:"env"`
	Cmd                    *exec.Cmd `json:"-"`
}

CapsuleProcess is a struct to describe a running Capsule process

func DuplicateProcessWithNewRevision

func DuplicateProcessWithNewRevision(functionName, newFunctionRevision string, index int, process CapsuleProcess) CapsuleProcess

DuplicateProcessWithNewRevision creates a new record with the same process (PID) but with different revision.

It takes in the function name, new function revision, an index, and a CapsuleProcess object. It returns a CapsuleProcess object.

func GetAllCapsuleProcessRecords

func GetAllCapsuleProcessRecords() []CapsuleProcess

GetAllCapsuleProcessRecords returns all the capsule process records.

None. []CapsuleProcess.

func GetCapsuleProcessRecord

func GetCapsuleProcessRecord(key string) (CapsuleProcess, error)

GetCapsuleProcessRecord retrieves the CapsuleProcess associated with a given key.

key string: the key to look up in the runningCapsules map. CapsuleProcess: the CapsuleProcess associated with the given key, or an empty CapsuleProcess if the key is not found.

func GetCapsuleProcessRecordsRelatedTo

func GetCapsuleProcessRecordsRelatedTo(functionName string) []CapsuleProcess

GetCapsuleProcessRecordsRelatedTo returns an array of CapsuleProcess records that are related to the given function name.

functionName: A string representing the name of the function to match. []CapsuleProcess: An array of CapsuleProcess records related to the given function name.

type CapsuleTask

type CapsuleTask struct {
	FunctionName     string   `json:"name"`
	FunctionRevision string   `json:"revision"`
	Description      string   `json:"description"`
	Path             string   `json:"path"`
	Args             []string `json:"args"`
	Env              []string `json:"env"`
}

CapsuleTask is a struct with the parameters to start a Capsule process

type Status

type Status int64

Status (of a task)

const (
	Waiting   Status = 0
	Started   Status = 1
	Finished  Status = 2
	Failed    Status = 3
	Cancelled Status = 4
	Stucked   Status = 5
	Killed    Status = 6
	Stopped   Status = 7
)

Enums of Status

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL