initial commit
This commit is contained in:
BIN
examples/runner
Executable file
BIN
examples/runner
Executable file
Binary file not shown.
34
examples/runner.vsh
Executable file
34
examples/runner.vsh
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import time
|
||||
import freeflowuniverse.herolib.baobab.runner
|
||||
import freeflowuniverse.herolib.core.redisclient
|
||||
|
||||
const namespace = ''
|
||||
|
||||
mut r := &runner.Runner{
|
||||
name: 'test_runner'
|
||||
redis_conn: redisclient.new('127.0.0.1:6379')!
|
||||
}
|
||||
|
||||
spawn r.run()
|
||||
|
||||
// job := runner.Job{
|
||||
// id: 'test_job_1'
|
||||
// caller_id: 'test_caller'
|
||||
// context_id: 'test_context_1'
|
||||
// runner: 'test_runner'
|
||||
// executor: 'tmux.session1'
|
||||
// payload: 'sleep 10\necho "Hello from job 1"\nsleep 10'
|
||||
// status: .dispatched
|
||||
// timeout: 30
|
||||
// created_at: time.now()
|
||||
// updated_at: time.now()
|
||||
// }
|
||||
|
||||
// mut redis_conn := redisclient.new('127.0.0.1:6379')!
|
||||
// job.store_in_redis(mut redis_conn, namespace)!
|
||||
// mut runner_q := redis_conn.queue_get(r.queue_key()!)
|
||||
// runner_q.add(job.id)!
|
||||
|
||||
for {}
|
107
examples/test_runner_rpc.vsh
Normal file
107
examples/test_runner_rpc.vsh
Normal file
@@ -0,0 +1,107 @@
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.redisclient
|
||||
import freeflowuniverse.herolib.baobab.runner
|
||||
import time
|
||||
import log
|
||||
|
||||
// Test script to send RPC calls over Redis to test the runner
|
||||
fn main() {
|
||||
log.info('Starting runner RPC test script')
|
||||
|
||||
// Connect to Redis
|
||||
mut redis := redisclient.new('127.0.0.1:6379')!
|
||||
|
||||
// Test runner configuration
|
||||
runner_name := 'test_runner'
|
||||
namespace := ''
|
||||
|
||||
// Create test jobs
|
||||
test_jobs := [
|
||||
runner.Job{
|
||||
id: 'test_job_1'
|
||||
caller_id: 'test_caller'
|
||||
context_id: 'test_context_1'
|
||||
runner: runner_name
|
||||
executor: 'tmux.session1'
|
||||
payload: 'echo "Hello from job 1"'
|
||||
status: .dispatched
|
||||
timeout: 30
|
||||
created_at: time.now()
|
||||
updated_at: time.now()
|
||||
},
|
||||
runner.Job{
|
||||
id: 'test_job_2'
|
||||
caller_id: 'test_caller'
|
||||
context_id: 'test_context_2'
|
||||
runner: runner_name
|
||||
executor: 'tmux.session2.window1'
|
||||
payload: 'ls -la && echo "Job 2 completed"'
|
||||
status: .dispatched
|
||||
timeout: 30
|
||||
created_at: time.now()
|
||||
updated_at: time.now()
|
||||
},
|
||||
runner.Job{
|
||||
id: 'test_job_3'
|
||||
caller_id: 'test_caller'
|
||||
context_id: 'test_context_3'
|
||||
runner: runner_name
|
||||
executor: 'tmux.session3.window1.pane1'
|
||||
payload: 'date && echo "Current time from job 3"'
|
||||
status: .dispatched
|
||||
timeout: 30
|
||||
created_at: time.now()
|
||||
updated_at: time.now()
|
||||
}
|
||||
]
|
||||
|
||||
log.info('Storing ${test_jobs.len} test jobs in Redis and dispatching to runner queue')
|
||||
|
||||
// Store jobs in Redis and dispatch them to the runner queue
|
||||
for job in test_jobs {
|
||||
// Store job data in Redis
|
||||
job.store_in_redis(mut redis, namespace) or {
|
||||
log.error('Failed to store job ${job.id}: ${err}')
|
||||
continue
|
||||
}
|
||||
|
||||
// Dispatch job to runner queue by pushing job ID to the queue
|
||||
queue_key := if namespace.len > 0 {
|
||||
"${namespace}:runner:${runner_name}"
|
||||
} else {
|
||||
"runner:${runner_name}"
|
||||
}
|
||||
|
||||
redis.rpush(queue_key, job.id) or {
|
||||
log.error('Failed to dispatch job ${job.id} to queue ${queue_key}: ${err}')
|
||||
continue
|
||||
}
|
||||
|
||||
log.info('Dispatched job ${job.id} to queue ${queue_key}')
|
||||
|
||||
// Small delay between jobs
|
||||
time.sleep(1 * time.second)
|
||||
}
|
||||
|
||||
log.info('All test jobs dispatched. Monitoring job status...')
|
||||
|
||||
// Monitor job status for a while
|
||||
for i in 0..30 { // Monitor for 30 seconds
|
||||
log.info('--- Status check ${i + 1} ---')
|
||||
|
||||
for job in test_jobs {
|
||||
loaded_job := runner.load_from_redis(mut redis, job.id, namespace) or {
|
||||
log.error('Failed to load job ${job.id}: ${err}')
|
||||
continue
|
||||
}
|
||||
|
||||
log.info('Job ${loaded_job.id}: status=${loaded_job.status}, result="${loaded_job.result}", error="${loaded_job.error}"')
|
||||
}
|
||||
|
||||
time.sleep(1 * time.second)
|
||||
}
|
||||
|
||||
log.info('Test completed. Check tmux sessions to see if commands were executed.')
|
||||
log.info('You can run "tmux list-sessions" to see created sessions.')
|
||||
}
|
Reference in New Issue
Block a user