memory

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package memory provides an in-memory implementation of the Job Distributor client.

This package is designed for testing purposes when you don't need a real JD backend. All data is stored in memory and is lost when the client is garbage collected.

Thread Safety

The MemoryJobDistributor implementation is thread-safe and uses sync.RWMutex to protect concurrent access to internal data structures. Multiple goroutines can safely call methods on the same MemoryJobDistributor instance concurrently.

Usage

Create a new in-memory JD client:

client := memory.NewMemoryJobDistributor()

Use it like any other JD client:

resp, err := client.ProposeJob(ctx, &jobv1.ProposeJobRequest{
    NodeId: "test-node",
    Spec:   "job spec here",
})

Limitations

- No persistence: All data is stored in memory only - Test-only: This implementation is intended for testing and should not be used in production environments

Implementation Details

The client maintains four in-memory maps:

  • jobs: Stores job instances by job ID
  • proposals: Stores job proposals by proposal ID
  • nodes: Stores node registrations by node ID
  • keypairs: Stores CSA keypairs by public key

All write operations (create, update, delete) modify these maps directly, and read operations return data from these maps.

Index

Constants

View Source
const (
	NodeVersion = "0.0.0.fake-node"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryJobDistributor

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

MemoryJobDistributor is an in-memory implementation of the Job Distributor client. It stores jobs, proposals, nodes, and keypairs in memory without persisting to any backend. This implementation is thread-safe and can be used concurrently from multiple goroutines.

func NewMemoryJobDistributor

func NewMemoryJobDistributor() *MemoryJobDistributor

NewMemoryJobDistributor creates a new in-memory Job Distributor client.

func (*MemoryJobDistributor) AddChainConfig

func (m *MemoryJobDistributor) AddChainConfig(nodeID string, config *nodev1.ChainConfig) error

AddChainConfig is a helper method to add chain configurations for testing purposes. This is not part of the standard interface but is useful for setting up test data.

func (*MemoryJobDistributor) AddKeypair

func (m *MemoryJobDistributor) AddKeypair(keypair *csav1.Keypair)

AddKeypair is a helper method to add a CSA keypair for testing purposes. This is not part of the standard interface but is useful for setting up test data.

func (*MemoryJobDistributor) BatchProposeJob

BatchProposeJob creates multiple job proposals in a batch.

func (*MemoryJobDistributor) DeleteJob

DeleteJob soft deletes a job, setting the DeletedAt field to the current time.

func (*MemoryJobDistributor) DisableNode

DisableNode disables a node.

func (*MemoryJobDistributor) EnableNode

EnableNode enables a disabled node.

func (*MemoryJobDistributor) GetJob

GetJob retrieves a job by its ID.

func (*MemoryJobDistributor) GetKeypair

GetKeypair retrieves the first CSA keypair (simulates getting the active keypair).

func (*MemoryJobDistributor) GetNode

GetNode retrieves a node by its ID.

func (*MemoryJobDistributor) GetProposal

GetProposal retrieves a proposal by its ID.

func (*MemoryJobDistributor) ListJobs

ListJobs returns all jobs stored in memory.

func (*MemoryJobDistributor) ListKeypairs

ListKeypairs returns all CSA keypairs stored in memory.

func (*MemoryJobDistributor) ListNodeChainConfigs

ListNodeChainConfigs returns chain configurations for nodes.

func (*MemoryJobDistributor) ListNodes

ListNodes returns all nodes stored in memory.

func (*MemoryJobDistributor) ListProposals

ListProposals returns all proposals stored in memory.

func (*MemoryJobDistributor) ProposeJob

ProposeJob creates a new job proposal and stores it in memory.

func (*MemoryJobDistributor) RegisterNode

RegisterNode registers a new node in memory.

func (*MemoryJobDistributor) RevokeJob

RevokeJob revokes an existing job proposal.

func (*MemoryJobDistributor) UpdateJob

UpdateJob updates an existing job in memory.

func (*MemoryJobDistributor) UpdateNode

UpdateNode updates an existing node in memory.

Jump to

Keyboard shortcuts

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