queue

package
v0.0.0-...-e2bd792 Latest Latest
Warning

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

Go to latest
Published: May 6, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STATUS_EMPTY     = "Empty"
	STATUS_RUNNING   = "Running"
	STATUS_PAUSED    = "Paused"
	STATUS_EXHAUSTED = "Exhausted"
)

Variables

View Source
var KeeperDuration time.Duration
View Source
var NetworkTimeout time.Duration
View Source
var StateFileLocation string

Functions

func HookOnJobCreate

func HookOnJobCreate(hooks []string, j common.Job)

Runs on Job Creation

func HookOnJobFinish

func HookOnJobFinish(hooks []string, j common.Job)

Runs when a job finishes no matter the status

func HookOnJobStart

func HookOnJobStart(hooks []string, j common.Job)

Runs on Job Start. Note: This is only when a job is initially started, * and will NOT pickup on pauses and restarts.

func HookOnQueueReorder

func HookOnQueueReorder(hooks []string, stack []common.Job)

Runs when the queue is reordered

func HookOnResourceConnect

func HookOnResourceConnect(hooks []string, id string, r Resource)

Runs when a resource is initially connected to the queue

Types

type HookJob

type HookJob struct {
	ID               string            `json:"id"`
	Name             string            `json:"name"`
	Status           string            `json:"status"`
	Owner            string            `json:"owner"`
	StartTime        time.Time         `json:"starttime"`
	CrackedHashes    int64             `json:"crackedhashes"`
	TotalHashes      int64             `json:"totalhashes"`
	Progress         float64           `json:"progress"`
	Params           map[string]string `json:"params"`
	ToolID           string            `json:"toolid"`
	PerformanceTitle string            `json:"performancetitle"`
	PerformanceData  map[string]string `json:"performancedata"`
	OutputTitles     []string          `json:"outputtitles"`
	OutputData       [][]string        `json:"outputdata"`
}

Jobs structure for hook

type HookParameters

type HookParameters struct {
	ScriptTimeout   int
	JobCreate       []string
	JobFinish       []string
	JobStart        []string
	ResourceConnect []string
	QueueReorder    []string
}

A struct that we can use as parameters to track our hooks from the configuration file down.

var Hooks HookParameters

type HookQueueOrder

type HookQueueOrder struct {
	JobOrder []HookQueueOrderJobData `json:"orderedjobs"`
}

type HookQueueOrderJobData

type HookQueueOrderJobData struct {
	ID            string    `json:"id"`
	Name          string    `json:"name"`
	Status        string    `json:"status"`
	Owner         string    `json:"owner"`
	StartTime     time.Time `json:"starttime"`
	CrackedHashes int64     `json:"crackedhashes"`
	TotalHashes   int64     `json:"totalhashes"`
	Progress      float64   `json:"progress"`
}

type HookResource

type HookResource struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	Address string `json:"address"`
}

Resource structure to be used for hooks

type Queue

type Queue struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue(statefile string, updatetime int, timeout int, hooks HookParameters, purgetime int) Queue

func (*Queue) ActiveTools

func (q *Queue) ActiveTools() map[string]common.Tool

This function allows you to get tools that can actively have jobs created for them

func (*Queue) AddJob

func (q *Queue) AddJob(j common.Job) error

Add a job to the queue at the end of the stack

func (*Queue) AddResource

func (q *Queue) AddResource(name string) (string, error)

This function will add a resource to the queue. Returns the UUID.

func (*Queue) AddResourceManager

func (q *Queue) AddResourceManager(resmgr ResourceManager) error

This function is used to add a resource manager to the map of all available managers and is used to add resourcemanager plugins during their creation.

func (*Queue) AllJobs

func (q *Queue) AllJobs() []common.Job

Get the full queue stack

func (*Queue) AllJobsByResource

func (q *Queue) AllJobsByResource(resourceid string) []common.Job

Get a list of all jobs assigned to a resource

func (*Queue) AllResourceManagers

func (q *Queue) AllResourceManagers() map[string]ResourceManager

This function is used to gather all currently available resource managers and provide them back to the API or any other needed functions.

func (*Queue) AllTools

func (q *Queue) AllTools() map[string]common.Tool

This function is used to get all tools that have ever been available

func (*Queue) CheckResourceConnectionStatus

func (q *Queue) CheckResourceConnectionStatus(res *Resource) bool

Checks to see if our RPC connection to a resource is still valid, if not it will return false, otherwise it will return true.

func (*Queue) ConnectResource

func (q *Queue) ConnectResource(resUUID, addr string, tlsconfig *tls.Config) error

This function will connect to a resource

func (*Queue) DeleteJobFromStackByIndex

func (q *Queue) DeleteJobFromStackByIndex(idx int)

func (*Queue) GetResource

func (q *Queue) GetResource(resUUID string) (*Resource, bool)

func (*Queue) GetResourceManager

func (q *Queue) GetResourceManager(systemname string) (ResourceManager, bool)

This function will return a copy of a single resource manager from the Queue and all of the associated etails. It takes a parameter of the system name of the manager desired.

func (*Queue) JobInfo

func (q *Queue) JobInfo(jobUUID string) common.Job

Get one specific job

func (*Queue) KeepAllResourceManagers

func (q *Queue) KeepAllResourceManagers()

This function will loop through all resource managers and executes thier keeper functions, causing them to update the status for all of their resources. The actions of each will be dependent on the resource manager.

func (*Queue) LoadRemoteResourceHardware

func (q *Queue) LoadRemoteResourceHardware(resUUID string)

This loads all of the hardware for a remote resource

func (*Queue) LoadRemoteResourceTools

func (q *Queue) LoadRemoteResourceTools(resUUID string)

func (*Queue) PauseJob

func (q *Queue) PauseJob(jobuuid string) error

func (*Queue) PauseQueue

func (q *Queue) PauseQueue() []error

Pause the whole queue and return any and all errors pausing active jobs/tasks

func (*Queue) PauseResource

func (q *Queue) PauseResource(resUUID string) error

func (*Queue) Quit

func (q *Queue) Quit() []common.Job

Quit the queue

func (*Queue) QuitJob

func (q *Queue) QuitJob(jobuuid string) error

func (*Queue) RemoveJob

func (q *Queue) RemoveJob(jobuuid string) error

func (*Queue) RemoveResource

func (q *Queue) RemoveResource(resUUID string) error

RemoveResource closes the resource RPC client, and removes it from service. It does not delete it however, because that information is needed by the API even after it is no longer in service.

func (*Queue) ResumeQueue

func (q *Queue) ResumeQueue()

func (*Queue) ResumeResource

func (q *Queue) ResumeResource(resUUID string) error

func (*Queue) StackReorder

func (q *Queue) StackReorder(uuids []string) error

Given a new slice of the UUIDs for all jobs in order, reorder the stack

func (*Queue) Types

func (q *Queue) Types() []string

type Resource

type Resource struct {
	Client   *rpc.Client
	Name     string
	Address  string
	Hardware map[string]bool
	Tools    map[string]common.Tool
	Status   string // Can be running, paused, quit
}

func NewResource

func NewResource() Resource

type ResourceManager

type ResourceManager interface {
	//SystemName returns the string used internally in the queue as a key.  This
	//should only use characters that are valid inside a URL.
	SystemName() string
	//DisplayName returns a string for the name that should be presented to humans
	DisplayName() string
	//Description returns a string with a short description of the resource manager
	Description() string
	//Parameters returns a string containing JSON objects
	//with the necessary information to add a new resource using this manager.
	//It will need to be in the same format as the tool parameters, using the
	//format specified at http://schemaform.io.  Consider that name and address
	//will be mandatory fields for when you add a resource, you may want to ask
	//for them, or you may want to generate them.
	ParametersForm() string
	ParametersSchema() string
	//AddResource takes a map of input (as required by parameters), the name and
	//address of the resource.  Finally, it also takes a tls configuration that
	//will be required by the Queue to connect to the resource.  It should then
	//add the resource to the queue itself for use by jobs.  Can return an error
	//but that will be nil is there were no issues.
	AddResource(params map[string]string) error
	//DeleteResource will remove a resource from the queue as soon as it is able
	//pending job completion.  Takes a parameter of the resource UUID and will
	//return an error if there are any problems.
	DeleteResource(resourceid string) error
	//GetResource takes the UUID of a resource in the queue and will return all
	//of the information about it in a queue.Resource object, as well as the
	//parameters that the resourcemanager is tracking internally.  Can also return
	//an error if there are any problems.
	GetResource(resourceid string) (*Resource, map[string]string, error)
	//Update resource allows the API to change the status of an existing resource
	//or update the parameters internal to the resource manager.  Address, name,
	//and other queue related resource data cannot be changed.
	UpdateResource(resourceid string, newstatus string, newparams map[string]string) error
	//GetManagedResources returns a slice of all resource UUIDs managed by this
	//resource manager.
	GetManagedResources() []string
	//Keep is a function that will be run on a regular basis (timing depends on
	//queue configuration, job status, etc.) and should process any ongoing needs
	//of the resource manager.  For example, the physical manager may attempt to
	//reconnect lost resources, or a Cloud based manager will stop resources that
	//have not been used in a set period of time to save money. Will be run
	//inside the main queue keeper synchronously.
	Keep()
}

The ResourceManager interface is used to implement functionality to manage * resources throughout the queue. All resource actions (add, remove, update) * will need to go through a manager, even for default or physical resources. * This interface is what the queue will expect for all manager operations. * Creation of managers should occur through the setup function, which takes * the path to the configuration file, and gets called when the Queue daemon is * setting everything up. The Setup function should return a ResourceManager * interface below for the Queue to use.

type ResourcePool

type ResourcePool map[string]Resource

func NewResourcePool

func NewResourcePool() ResourcePool

type StateFile

type StateFile struct {
	Stack []common.Job `json:"stack"`
	Pool  ResourcePool `json:"pool"`
}

type Stats

type Stats struct {
	// contains filtered or unexported fields
}

func NewStats

func NewStats() Stats

func (*Stats) IncJob

func (s *Stats) IncJob()

func (*Stats) JobCount

func (s *Stats) JobCount() int64

Jump to

Keyboard shortcuts

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