timecraft

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const TimecraftAddress = "127.0.0.1:7463"

TimecraftAddress is the socket that timecraft guests connect to in order to interact with the timecraft runtime on the host. Note that this is a virtual socket.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a timecraft client.

func NewClient

func NewClient() (*Client, error)

NewClient creates a timecraft client.

func (*Client) DiscardTasks

func (c *Client) DiscardTasks(ctx context.Context, taskIDs []TaskID) error

DiscardTasks discards a batch of tasks by ID.

func (*Client) Kill

func (c *Client) Kill(ctx context.Context, processID ProcessID) error

Kill kills a process.

func (*Client) Logger

func (c *Client) Logger() *log.Logger

Logger returns a logger that includes the process ID in log output.

func (*Client) LookupTasks

func (c *Client) LookupTasks(ctx context.Context, taskIDs []TaskID) ([]TaskResponse, error)

LookupTasks retrieves task responses by ID.

func (*Client) PollTasks

func (c *Client) PollTasks(ctx context.Context, batchSize int, timeout time.Duration) ([]TaskResponse, error)

PollTasks retrieves tasks that are complete.

Tasks are complete when task execution either succeeds or fails permanently.

PollTasks will block the goroutine until either batchSize tasks are complete, or the timeout is reached, whichever comes first. If timeout is zero, the timecraft runtime won't block waiting for complete tasks. If the timeout is less than zero, the method will block until batchSize tasks are complete (and thus may block indefinitely).

func (*Client) ProcessID

func (c *Client) ProcessID(ctx context.Context) (ProcessID, error)

ProcessID fetches the ID of the process.

func (*Client) Spawn

func (c *Client) Spawn(ctx context.Context, module ModuleSpec) (ProcessID, netip.Addr, error)

Spawn spawns a process.

func (*Client) SubmitTasks

func (c *Client) SubmitTasks(ctx context.Context, requests []TaskRequest) ([]TaskID, error)

SubmitTasks submits tasks to the timecraft runtime.

The tasks are executed asynchronously. The method returns a set of TaskID that can be used to query task status and fetch task output when ready.

func (*Client) Version

func (c *Client) Version(ctx context.Context) (string, error)

Version fetches the Timecraft version.

type HTTPRequest

type HTTPRequest struct {
	Method  string
	Path    string
	Headers http.Header
	Body    []byte
	Port    int
}

HTTPRequest is an HTTP request.

type HTTPResponse

type HTTPResponse struct {
	StatusCode int
	Headers    http.Header
	Body       []byte
}

HTTPResponse is an HTTP response.

type ModuleSpec

type ModuleSpec struct {
	Path          string
	Function      string
	Args          []string
	Env           []string
	OutboundProxy *ModuleSpec
}

ModuleSpec is a WebAssembly module specification.

type ProcessID

type ProcessID string

ProcessID is a process identifier.

type TaskID

type TaskID string

TaskID is a task identifier.

type TaskInput

type TaskInput interface {
	// contains filtered or unexported methods
}

TaskInput is input to a task.

type TaskOutput

type TaskOutput interface {
	// contains filtered or unexported methods
}

TaskOutput is output from a task.

type TaskRequest

type TaskRequest struct {
	// Module is details about the WebAssembly module that's responsible
	// for executing the task.
	Module ModuleSpec

	// Input is input to the task.
	Input TaskInput
}

TaskRequest is a request to the timecraft runtime asking it to schedule a task for execution.

type TaskResponse

type TaskResponse struct {
	// ID is the task identifier.
	ID TaskID

	// State is the current state of the task.
	State TaskState

	// Error is the error that occurred during task initialization or execution
	// (if applicable).
	Error error

	// Output is the output of the task, if it executed successfully.
	Output TaskOutput

	// ProcessID is the identifier of the process that handled the task
	// (if applicable).
	ProcessID ProcessID
}

TaskResponse is information about a task from the timecraft runtime.

type TaskState

type TaskState int

TaskState is the state of a task.

const (
	// Queued indicates that the task is waiting to be scheduled.
	Queued TaskState = iota + 1

	// Initializing indicates that the task is in the process of being scheduled
	// on to a process.
	Initializing

	// Executing indicates that the task is currently being executed.
	Executing

	// Error indicates that the task failed with an error. This is a terminal
	// status.
	Error

	// Success indicates that the task executed successfully. This is a terminal
	// status.
	Success
)

Jump to

Keyboard shortcuts

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