38 lines
921 B
Plaintext
38 lines
921 B
Plaintext
import os
|
|
import incubaid.herolib.baobab.stage
|
|
import incubaid.herolib.core.redisclient
|
|
import incubaid.herolib.schemas.openapi
|
|
|
|
const name = '@{actor_name_snake}'
|
|
|
|
@@[heap]
|
|
struct @{actor_name_pascal}Actor {
|
|
stage.Actor
|
|
}
|
|
|
|
pub fn new() !&@{actor_name_pascal}Actor {
|
|
return &@{actor_name_pascal}Actor {
|
|
Actor: stage.new_actor('example_@{actor_name_snake}')!
|
|
}
|
|
}
|
|
|
|
pub fn (mut a @{actor_name_pascal}Actor) handle(method string, data string) !string {
|
|
action := a.act(
|
|
name: method
|
|
params: data
|
|
)!
|
|
return action.result
|
|
}
|
|
|
|
// Actor listens to the Redis queue for method invocations
|
|
pub fn (mut a @{actor_name_pascal}Actor) run() ! {
|
|
mut redis := redisclient.new('localhost:6379') or { panic(err) }
|
|
mut rpc := redis.rpc_get('actor_@{dollar}{a.name}')
|
|
|
|
println('Actor started and listening for tasks...')
|
|
for {
|
|
rpc.process(a.handle)!
|
|
time.sleep(time.millisecond * 100) // Prevent CPU spinning
|
|
}
|
|
}
|