Skip to content

hero.actionprocessor #

fn action_job_from_json #

fn action_job_from_json(data string) !ActionJob

from_json creates an ActionJob from a JSON string

fn get_action_queue #

fn get_action_queue(name string) !&ActionQueue

get_action_queue retrieves an existing ActionQueue or creates a new one

fn new #

fn new(args_ CircleCoordinatorArgs) !&CircleCoordinator

new creates a new CircleCoordinator instance

fn new_action_job #

fn new_action_job(heroscript string) ActionJob

new_action_job creates a new ActionJob with the given heroscript

fn new_action_job_with_deadline #

fn new_action_job_with_deadline(heroscript string, deadline_str string) !ActionJob

new_action_job_with_deadline creates a new ActionJob with the given heroscript and deadline

fn new_action_queue #

fn new_action_queue(args ActionQueueArgs) !&ActionQueue

new_action_queue creates a new ActionQueue

enum ActionJobStatus #

enum ActionJobStatus {
	pending
	processing
	completed
	failed
	cancelled
}

ActionJobStatus represents the current status of an action job

struct ActionJob #

@[heap]
struct ActionJob {
pub mut:
	guid       string
	heroscript string
	created    ourtime.OurTime
	deadline   ourtime.OurTime
	status     ActionJobStatus
	error      string // Error message if job failed
	async      bool   // Whether the job should be processed asynchronously
	circleid   string // ID of the circle this job belongs to
}

ActionJob represents a job to be processed by the action processor

fn (ActionJob) to_json #

fn (job ActionJob) to_json() string

to_json converts the ActionJob to a JSON string

fn (ActionJob) to_playbook #

fn (job ActionJob) to_playbook() !&playbook.PlayBook

to_playbook converts the job's heroscript to a PlayBook object

struct ActionQueue #

@[heap]
struct ActionQueue {
pub mut:
	name  string
	queue &redisclient.RedisQueue
	redis &redisclient.Redis
}

ActionQueue is a queue of actions to be processed, which comes from a redis queue

fn (ActionQueue) add_job #

fn (mut q ActionQueue) add_job(job ActionJob) !

add adds a job to the queue

fn (ActionQueue) get_job #

fn (mut q ActionQueue) get_job(guid string) !ActionJob

get_job retrieves a job from Redis by its GUID

fn (ActionQueue) update_job_status #

fn (mut q ActionQueue) update_job_status(guid string, status ActionJobStatus) !

update_job_status updates the status of a job in Redis

fn (ActionQueue) set_job_failed #

fn (mut q ActionQueue) set_job_failed(guid string, error_msg string) !

set_job_failed marks a job as failed with an error message

fn (ActionQueue) count_waiting_jobs #

fn (mut q ActionQueue) count_waiting_jobs() !int

count_waiting_jobs returns the number of jobs waiting in the queue

fn (ActionQueue) find_failed_jobs #

fn (mut q ActionQueue) find_failed_jobs() ![]ActionJob

find_failed_jobs returns a list of failed jobs

fn (ActionQueue) delete_job #

fn (mut q ActionQueue) delete_job(guid string) !

delete_job deletes a job from Redis

fn (ActionQueue) add #

fn (mut q ActionQueue) add(val string) !

add adds a string value to the queue

fn (ActionQueue) get #

fn (mut q ActionQueue) get(timeout u64) !string

get retrieves a value from the queue with timeout timeout in msec

fn (ActionQueue) pop #

fn (mut q ActionQueue) pop() !string

pop retrieves a value from the queue without timeout get without timeout, returns none if nil

fn (ActionQueue) fetch_job #

fn (mut q ActionQueue) fetch_job(timeout u64) !ActionJob

fetch_job retrieves the next job from the queue

fn (ActionQueue) pop_job #

fn (mut q ActionQueue) pop_job() !ActionJob

pop_job retrieves the next job from the queue without timeout

fn (ActionQueue) delete #

fn (mut q ActionQueue) delete() !

delete clears the queue (removes all items)

struct ActionQueueArgs #

@[params]
struct ActionQueueArgs {
pub mut:
	name       string = 'default' // Name of the queue
	redis_addr string // Redis server address, defaults to 'localhost:6379'
}

ActionQueueArgs defines the parameters for creating a new ActionQueue

struct CircleCoordinator #

@[heap]
struct CircleCoordinator {
pub mut:
	name          string // is a unique name on planetary scale is a dns name
	agents        &core_db.AgentDB
	circles       &core_db.CircleDB
	names         &core_db.NameDB
	mails         &mcc_db.MailDB
	calendar      &mcc_db.CalendarDB
	jobs          &actions_db.JobDB
	action_queues map[string]&ActionQueue
	session_state SessionState
}

HeroRunner is the main factory for managing jobs, agents, services, circles and names

fn (CircleCoordinator) get_or_create_action_queue #

fn (mut cc CircleCoordinator) get_or_create_action_queue(name string) !&ActionQueue

get_or_create_action_queue retrieves an existing ActionQueue for a CircleCoordinator or creates a new one

struct CircleCoordinatorArgs #

@[params]
struct CircleCoordinatorArgs {
pub mut:
	name   string = 'local'
	pubkey string // pubkey of user who called this
	addr   string // mycelium address
	path   string
}