...
This commit is contained in:
18
specs/model/actor.v
Normal file
18
specs/model/actor.v
Normal file
@@ -0,0 +1,18 @@
|
||||
module model
|
||||
|
||||
// a actor is a participant in the new internet, the one who can ask for work
|
||||
// user can have more than one actor operating for them, an actor always operates in a context which is hosted by the hero of the user
|
||||
// stored in the context db at actor:<id> (actor is hset)
|
||||
@[heap]
|
||||
pub struct Actor {
|
||||
pub mut:
|
||||
id u32
|
||||
pubkey string
|
||||
address []Address // address (is to reach the actor back), normally mycelium but doesn't have to be
|
||||
created_at u32 // epoch
|
||||
updated_at u32 // epoch
|
||||
}
|
||||
|
||||
pub fn (self Actor) redis_key() string {
|
||||
return 'actor:${self.id}'
|
||||
}
|
20
specs/model/context.v
Normal file
20
specs/model/context.v
Normal file
@@ -0,0 +1,20 @@
|
||||
module model
|
||||
|
||||
// each job is run in a context, this corresponds to a DB in redis and has specific rights to actors
|
||||
// context is a redis db and also a locaction on a filesystem which can be used for e.g. logs, temporary files, etc.
|
||||
// actors create contexts for others to work in
|
||||
// stored in the context db at context:<id> (context is hset)
|
||||
@[heap]
|
||||
pub struct Context {
|
||||
pub mut:
|
||||
id u32 // corresponds with the redis db (in our ourdb or other redis)
|
||||
admins []u32 // actors which have admin rights on this context (means can do everything)
|
||||
readers []u32 // actors which can read the context info
|
||||
executors []u32 // actors which can execute jobs in this context
|
||||
created_at u32 // epoch
|
||||
updated_at u32 // epoch
|
||||
}
|
||||
|
||||
pub fn (self Context) redis_key() string {
|
||||
return 'context:${self.id}'
|
||||
}
|
41
specs/model/flow.v
Normal file
41
specs/model/flow.v
Normal file
@@ -0,0 +1,41 @@
|
||||
module model
|
||||
|
||||
// what get's executed by an actor and needs to be tracked as a whole, can be represented as a DAG graph
|
||||
// this is the high level representation of a workflow to execute on work, its fully decentralized and distributed
|
||||
// only the actor who created the flow can modify it and holds it in DB
|
||||
// stored in the context db at flow:<id> (flow is hset)
|
||||
@[heap]
|
||||
pub struct Flow {
|
||||
pub mut:
|
||||
id u32 // this job id is given by the actor who called for it
|
||||
caller_id u32 // is the actor which called for this job
|
||||
context_id u32 // each job is executed in a context
|
||||
jobs []u32 // links to all jobs which make up this flow, this can be dynamically modified
|
||||
env_vars map[string]string // they are copied to every job done
|
||||
result map[string]string // the result of the flow
|
||||
created_at u32 // epoch
|
||||
updated_at u32 // epoch
|
||||
status FlowStatus
|
||||
}
|
||||
|
||||
pub fn (self Flow) redis_key() string {
|
||||
return 'flow:${self.id}'
|
||||
}
|
||||
|
||||
// FlowStatus represents the status of a flow
|
||||
pub enum FlowStatus {
|
||||
dispatched
|
||||
started
|
||||
error
|
||||
finished
|
||||
}
|
||||
|
||||
// str returns the string representation of FlowStatus
|
||||
pub fn (self FlowStatus) str() string {
|
||||
return match self {
|
||||
.dispatched { 'dispatched' }
|
||||
.started { 'started' }
|
||||
.error { 'error' }
|
||||
.finished { 'finished' }
|
||||
}
|
||||
}
|
68
specs/model/message.v
Normal file
68
specs/model/message.v
Normal file
@@ -0,0 +1,68 @@
|
||||
module model
|
||||
|
||||
// Messages is what goes over mycelium (which is our messaging system), they can have a job inside
|
||||
// stored in the context db at msg:<callerid>:<id> (msg is hset)
|
||||
// there are 2 queues in the context db: queue: msg_out and msg_in these are generic queues which get all messages from mycelium (in) and the ones who need to be sent (out) are in the outqueue
|
||||
@[heap]
|
||||
pub struct Message {
|
||||
pub mut:
|
||||
id u32 // is unique id for the message, has been given by the caller
|
||||
caller_id u32 // is the actor whos send this message
|
||||
context_id u32 // each message is for a specific context
|
||||
message string
|
||||
message_type ScriptType
|
||||
message_format_type MessageFormatType
|
||||
timeout u32 // in sec, to arrive destination
|
||||
timeout_ack u32 // in sec, to acknowledge receipt
|
||||
timeout_result u32 // in sec, to process result and have it back
|
||||
job []Job
|
||||
logs []Log // e.g. for streaming logs back to originator
|
||||
created_at u32 // epoch
|
||||
updated_at u32 // epoch
|
||||
status MessageStatus
|
||||
}
|
||||
|
||||
// MessageType represents the type of message
|
||||
pub enum MessageType {
|
||||
job
|
||||
chat
|
||||
mail
|
||||
}
|
||||
|
||||
// MessageFormatType represents the format of a message
|
||||
pub enum MessageFormatType {
|
||||
html
|
||||
text
|
||||
md
|
||||
}
|
||||
|
||||
pub fn (self Message) redis_key() string {
|
||||
return 'message:${self.caller_id}:${self.id}'
|
||||
}
|
||||
|
||||
// queue_suffix returns the queue suffix for the message type
|
||||
pub fn (mt MessageType) queue_suffix() string {
|
||||
return match mt {
|
||||
.job { 'job' }
|
||||
.chat { 'chat' }
|
||||
.mail { 'mail' }
|
||||
}
|
||||
}
|
||||
|
||||
// MessageStatus represents the status of a message
|
||||
pub enum MessageStatus {
|
||||
dispatched
|
||||
acknowledged
|
||||
error
|
||||
processed // e.g. can be something which comes back
|
||||
}
|
||||
|
||||
// str returns the string representation of MessageStatus
|
||||
pub fn (ms MessageStatus) str() string {
|
||||
return match ms {
|
||||
.dispatched { 'dispatched' }
|
||||
.acknowledged { 'acknowledged' }
|
||||
.error { 'error' }
|
||||
.processed { 'processed' }
|
||||
}
|
||||
}
|
27
specs/model/runner.v
Normal file
27
specs/model/runner.v
Normal file
@@ -0,0 +1,27 @@
|
||||
module model
|
||||
|
||||
// a runner executes a job, this can be in VM, in a container or just some processes running somewhere
|
||||
// the messages always come in over a topic
|
||||
// stored in the context db at runner:<id> (runner is hset)
|
||||
@[heap]
|
||||
pub struct Runner {
|
||||
pub mut:
|
||||
id u32
|
||||
pubkey string // from mycelium
|
||||
address string // mycelium address
|
||||
topic string // needs to be set by the runner but often runner<runnerid> e.g. runner20
|
||||
local bool // if local then goes on redis using the id
|
||||
created_at u32 // epoch
|
||||
updated_at u32 // epoch
|
||||
}
|
||||
|
||||
pub enum RunnerType {
|
||||
v
|
||||
python
|
||||
osis
|
||||
rust
|
||||
}
|
||||
|
||||
pub fn (self Runner) redis_key() string {
|
||||
return 'runner:${self.id}'
|
||||
}
|
64
specs/model/runnerjob.v
Normal file
64
specs/model/runnerjob.v
Normal file
@@ -0,0 +1,64 @@
|
||||
module model
|
||||
|
||||
// Job represents a job, a job is only usable in the context of a runner (which is part of a hero)
|
||||
// stored in the context db at job:<callerid>:<id> (job is hset)
|
||||
@[heap]
|
||||
pub struct RunnerJob {
|
||||
pub mut:
|
||||
id u32 // this job id is given by the actor who called for it
|
||||
caller_id u32 // is the actor which called for this job
|
||||
context_id u32 // each job is executed in a context
|
||||
script string
|
||||
script_type ScriptType
|
||||
timeout u32 // in sec
|
||||
retries u8
|
||||
env_vars map[string]string
|
||||
result map[string]string
|
||||
prerequisites []string
|
||||
dependends []u32
|
||||
created_at u32 // epoch
|
||||
updated_at u32 // epoch
|
||||
status JobStatus
|
||||
}
|
||||
|
||||
// ScriptType represents the type of script
|
||||
pub enum ScriptType {
|
||||
osis
|
||||
sal
|
||||
v
|
||||
python
|
||||
}
|
||||
|
||||
pub fn (self RunnerJob) redis_key() string {
|
||||
return 'job:${self.caller_id}:${self.id}'
|
||||
}
|
||||
|
||||
// queue_suffix returns the queue suffix for the script type
|
||||
pub fn (st ScriptType) queue_suffix() string {
|
||||
return match st {
|
||||
.osis { 'osis' }
|
||||
.sal { 'sal' }
|
||||
.v { 'v' }
|
||||
.python { 'python' }
|
||||
}
|
||||
}
|
||||
|
||||
// JobStatus represents the status of a job
|
||||
pub enum JobStatus {
|
||||
dispatched
|
||||
waiting_for_prerequisites
|
||||
started
|
||||
error
|
||||
finished
|
||||
}
|
||||
|
||||
// str returns the string representation of JobStatus
|
||||
pub fn (js JobStatus) str() string {
|
||||
return match js {
|
||||
.dispatched { 'dispatched' }
|
||||
.waiting_for_prerequisites { 'waiting_for_prerequisites' }
|
||||
.started { 'started' }
|
||||
.error { 'error' }
|
||||
.finished { 'finished' }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user