...
This commit is contained in:
@@ -38,6 +38,10 @@ fn do() ! {
|
||||
|
||||
if os.args.len == 2 {
|
||||
mypath := os.args[1]
|
||||
if mypath == '.' {
|
||||
playcmds_do(os.getwd())!
|
||||
return
|
||||
}
|
||||
if mypath.to_lower().ends_with('.hero') || mypath.to_lower().ends_with('.heroscript')
|
||||
|| mypath.to_lower().ends_with('.hs') {
|
||||
// hero was called from a file
|
||||
@@ -82,7 +86,6 @@ fn do() ! {
|
||||
|
||||
base.redis_install()!
|
||||
|
||||
herocmds.cmd_run(mut cmd)
|
||||
herocmds.cmd_git(mut cmd)
|
||||
herocmds.cmd_generator(mut cmd)
|
||||
herocmds.cmd_docusaurus(mut cmd)
|
||||
@@ -101,7 +104,3 @@ fn main() {
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// fn pre_func(cmd Command) ! {
|
||||
// herocmds.plbook_run(cmd)!
|
||||
// }
|
||||
@@ -1,2 +1 @@
|
||||
!!git.check
|
||||
filter: 'test_repo'
|
||||
!!git.check filter:'herolib'
|
||||
@@ -1,84 +0,0 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import incubaid.herolib.core.jobs.model
|
||||
import flag
|
||||
import os
|
||||
import time
|
||||
|
||||
// This example demonstrates using the VFS-based job storage
|
||||
// - Creating jobs and storing them in VFS
|
||||
// - Listing jobs from VFS
|
||||
// - Cleaning up old jobs
|
||||
|
||||
mut fp := flag.new_flag_parser(os.args)
|
||||
fp.application('vfs_jobs_example.vsh')
|
||||
fp.version('v0.1.0')
|
||||
fp.description('Example of VFS-based job storage with cleanup functionality')
|
||||
fp.skip_executable()
|
||||
|
||||
cleanup_days := fp.int('days', `d`, 7, 'Clean up jobs older than this many days')
|
||||
create_count := fp.int('create', `c`, 5, 'Number of jobs to create')
|
||||
help_requested := fp.bool('help', `h`, false, 'Show help message')
|
||||
|
||||
if help_requested {
|
||||
println(fp.usage())
|
||||
exit(0)
|
||||
}
|
||||
|
||||
additional_args := fp.finalize() or {
|
||||
eprintln(err)
|
||||
println(fp.usage())
|
||||
exit(1)
|
||||
}
|
||||
|
||||
// Create a new HeroRunner instance
|
||||
mut runner := model.new() or { panic('Failed to create HeroRunner: ${err}') }
|
||||
|
||||
println('\n---------BEGIN VFS JOBS EXAMPLE')
|
||||
|
||||
// Create some jobs
|
||||
println('\n---------CREATING JOBS')
|
||||
for i in 0 .. create_count {
|
||||
mut job := runner.jobs.new()
|
||||
job.guid = 'job_${i}_${time.now().unix}'
|
||||
job.actor = 'example_actor'
|
||||
job.action = 'test_action'
|
||||
job.params = {
|
||||
'param1': 'value1'
|
||||
'param2': 'value2'
|
||||
}
|
||||
|
||||
// For demonstration, make some jobs older by adjusting their creation time
|
||||
if i % 2 == 0 {
|
||||
job.status.created.time = time.now().add_days(-(cleanup_days + 1))
|
||||
}
|
||||
|
||||
runner.jobs.set(job) or { panic('Failed to set job: ${err}') }
|
||||
println('Created job with GUID: ${job.guid}')
|
||||
}
|
||||
|
||||
// List all jobs
|
||||
println('\n---------LISTING ALL JOBS')
|
||||
jobs := runner.jobs.list() or { panic('Failed to list jobs: ${err}') }
|
||||
println('Found ${jobs.len} jobs:')
|
||||
for job in jobs {
|
||||
days_ago := (time.now().unix - job.status.created.time.unix) / (60 * 60 * 24)
|
||||
println('- ${job.guid} (created ${days_ago} days ago)')
|
||||
}
|
||||
|
||||
// Clean up old jobs
|
||||
println('\n---------CLEANING UP OLD JOBS')
|
||||
println('Cleaning up jobs older than ${cleanup_days} days...')
|
||||
deleted_count := runner.cleanup_jobs(cleanup_days) or { panic('Failed to clean up jobs: ${err}') }
|
||||
println('Deleted ${deleted_count} old jobs')
|
||||
|
||||
// List remaining jobs
|
||||
println('\n---------LISTING REMAINING JOBS')
|
||||
remaining_jobs := runner.jobs.list() or { panic('Failed to list jobs: ${err}') }
|
||||
println('Found ${remaining_jobs.len} remaining jobs:')
|
||||
for job in remaining_jobs {
|
||||
days_ago := (time.now().unix - job.status.created.time.unix) / (60 * 60 * 24)
|
||||
println('- ${job.guid} (created ${days_ago} days ago)')
|
||||
}
|
||||
|
||||
println('\n---------END VFS JOBS EXAMPLE')
|
||||
14
install_v.sh
14
install_v.sh
@@ -444,7 +444,17 @@ check_and_start_redis() {
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
|
||||
if command_exists zinit; then
|
||||
# Check if redis service is managed by zinit and is running
|
||||
if zinit status redis | grep -q "state: Running"; then
|
||||
echo "redis is already running and managed by zinit."
|
||||
return
|
||||
else
|
||||
echo "zinit is installed, but redis is not running or not managed by zinit. Proceeding with other checks."
|
||||
fi
|
||||
fi
|
||||
|
||||
if systemctl is-active --quiet "redis"; then
|
||||
echo "redis is already running."
|
||||
else
|
||||
@@ -631,7 +641,7 @@ if [ "$RESET" = true ] || ! command_exists v; then
|
||||
|
||||
fi
|
||||
|
||||
|
||||
# set -x
|
||||
check_and_start_redis
|
||||
|
||||
if [ "$HEROLIB" = true ]; then
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&GiteaClient {
|
||||
if r.hexists('context:giteaclient', args.name)! {
|
||||
data := r.hget('context:giteaclient', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('GiteaClient with name: giteaclient does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(GiteaClient, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&GiteaClient {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("GiteaClient with name 'giteaclient' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return giteaclient_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for giteaclient with name:giteaclient')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'giteaclient.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&IPApi {
|
||||
if r.hexists('context:ipapi', args.name)! {
|
||||
data := r.hget('context:ipapi', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('IPApi with name: ipapi does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(IPApi, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&IPApi {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("IPApi with name 'ipapi' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return ipapi_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for ipapi with name:ipapi')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'ipapi.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&Jina {
|
||||
if r.hexists('context:jina', args.name)! {
|
||||
data := r.hget('context:jina', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('Jina with name: jina does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(Jina, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&Jina {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("Jina with name 'jina' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return jina_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for jina with name:jina')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'jina.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&LivekitClient {
|
||||
if r.hexists('context:livekit', args.name)! {
|
||||
data := r.hget('context:livekit', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('LivekitClient with name: livekit does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(LivekitClient, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&LivekitClient {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("LivekitClient with name 'livekit' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return livekit_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for livekit with name:livekit')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'livekit.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&MailClient {
|
||||
if r.hexists('context:mailclient', args.name)! {
|
||||
data := r.hget('context:mailclient', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('MailClient with name: mailclient does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(MailClient, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&MailClient {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("MailClient with name 'mailclient' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return mailclient_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for mailclient with name:mailclient')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'mailclient.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&MeilisearchClient {
|
||||
if r.hexists('context:meilisearch', args.name)! {
|
||||
data := r.hget('context:meilisearch', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('MeilisearchClient with name: meilisearch does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(MeilisearchClient, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&MeilisearchClient {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("MeilisearchClient with name 'meilisearch' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return meilisearch_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for meilisearch with name:meilisearch')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'meilisearch.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ module mycelium
|
||||
|
||||
import incubaid.herolib.core.base
|
||||
import incubaid.herolib.core.playbook { PlayBook }
|
||||
import incubaid.herolib.ui.console
|
||||
import json
|
||||
|
||||
__global (
|
||||
@@ -35,6 +36,7 @@ pub fn get(args ArgsGet) !&Mycelium {
|
||||
if r.hexists('context:mycelium', args.name)! {
|
||||
data := r.hget('context:mycelium', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('Mycelium with name: mycelium does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(Mycelium, data)!
|
||||
@@ -43,12 +45,14 @@ pub fn get(args ArgsGet) !&Mycelium {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("Mycelium with name 'mycelium' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return mycelium_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for mycelium with name:mycelium')
|
||||
}
|
||||
}
|
||||
@@ -121,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'mycelium.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&MyceliumRPC {
|
||||
if r.hexists('context:mycelium_rpc', args.name)! {
|
||||
data := r.hget('context:mycelium_rpc', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('MyceliumRPC with name: mycelium_rpc does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(MyceliumRPC, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&MyceliumRPC {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("MyceliumRPC with name 'mycelium_rpc' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return mycelium_rpc_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for mycelium_rpc with name:mycelium_rpc')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'mycelium_rpc.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&OpenAI {
|
||||
if r.hexists('context:openai', args.name)! {
|
||||
data := r.hget('context:openai', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('OpenAI with name: openai does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(OpenAI, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&OpenAI {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("OpenAI with name 'openai' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return openai_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for openai with name:openai')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'openai.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&PostgresqlClient {
|
||||
if r.hexists('context:postgresql_client', args.name)! {
|
||||
data := r.hget('context:postgresql_client', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('PostgresqlClient with name: postgresql_client does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(PostgresqlClient, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&PostgresqlClient {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("PostgresqlClient with name 'postgresql_client' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return postgresql_client_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for postgresql_client with name:postgresql_client')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'postgresql_client.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&QDrantClient {
|
||||
if r.hexists('context:qdrant', args.name)! {
|
||||
data := r.hget('context:qdrant', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('QDrantClient with name: qdrant does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(QDrantClient, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&QDrantClient {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("QDrantClient with name 'qdrant' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return qdrant_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for qdrant with name:qdrant')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'qdrant.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&RCloneClient {
|
||||
if r.hexists('context:rclone', args.name)! {
|
||||
data := r.hget('context:rclone', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('RCloneClient with name: rclone does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(RCloneClient, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&RCloneClient {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("RCloneClient with name 'rclone' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return rclone_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for rclone with name:rclone')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'rclone.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&RunPod {
|
||||
if r.hexists('context:runpod', args.name)! {
|
||||
data := r.hget('context:runpod', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('RunPod with name: runpod does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(RunPod, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&RunPod {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("RunPod with name 'runpod' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return runpod_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for runpod with name:runpod')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'runpod.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&SendGrid {
|
||||
if r.hexists('context:sendgrid', args.name)! {
|
||||
data := r.hget('context:sendgrid', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('SendGrid with name: sendgrid does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(SendGrid, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&SendGrid {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("SendGrid with name 'sendgrid' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return sendgrid_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for sendgrid with name:sendgrid')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'sendgrid.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&VastAI {
|
||||
if r.hexists('context:vastai', args.name)! {
|
||||
data := r.hget('context:vastai', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('VastAI with name: vastai does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(VastAI, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&VastAI {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("VastAI with name 'vastai' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return vastai_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for vastai with name:vastai')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'vastai.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&WireGuard {
|
||||
if r.hexists('context:wireguard', args.name)! {
|
||||
data := r.hget('context:wireguard', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('WireGuard with name: wireguard does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(WireGuard, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&WireGuard {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("WireGuard with name 'wireguard' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return wireguard_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for wireguard with name:wireguard')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'wireguard.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&ZeroDBClient {
|
||||
if r.hexists('context:zerodb_client', args.name)! {
|
||||
data := r.hget('context:zerodb_client', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('ZeroDBClient with name: zerodb_client does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(ZeroDBClient, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&ZeroDBClient {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("ZeroDBClient with name 'zerodb_client' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return zerodb_client_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for zerodb_client with name:zerodb_client')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'zerodb_client.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&ZinitRPC {
|
||||
if r.hexists('context:zinit', args.name)! {
|
||||
data := r.hget('context:zinit', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('ZinitRPC with name: zinit does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(ZinitRPC, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&ZinitRPC {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("ZinitRPC with name 'zinit' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return zinit_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for zinit with name:zinit')
|
||||
}
|
||||
}
|
||||
@@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'zinit.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ pub fn generate(args_ GeneratorArgs) ! {
|
||||
console.print_header('Generate code for path: ${args.path} (reset:${args.force}, force:${args.force})')
|
||||
console.print_debug(args)
|
||||
if args.path == '' {
|
||||
args.path = os.getwd()
|
||||
return error('no path provided')
|
||||
}
|
||||
|
||||
if args.name == '' {
|
||||
|
||||
@@ -21,10 +21,19 @@ pub fn scan(args_ GeneratorArgs) ! {
|
||||
regex: ['.heroscript']
|
||||
)!
|
||||
|
||||
console.print_debug('Found ${plist.paths.len} directories with .heroscript file.')
|
||||
for mut p in plist.paths {
|
||||
pparent := p.parent()!
|
||||
args.force = true
|
||||
args.path = pparent.path
|
||||
// println("-- ${pparent}")
|
||||
generate(args)!
|
||||
}
|
||||
mut res := []GeneratorArgs{}
|
||||
for mut p in plist.paths {
|
||||
pparent := p.parent()!
|
||||
res << args_get(pparent.path)!
|
||||
}
|
||||
console.print_debug('Found ${res.len} generator args.')
|
||||
println(res)
|
||||
$dbg;
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import cli { Command, Flag }
|
||||
|
||||
pub fn cmd_generator(mut cmdroot Command) {
|
||||
mut cmd_run := Command{
|
||||
name: 'generate'
|
||||
description: 'generator for vlang code in hero context.'
|
||||
required_args: 0
|
||||
execute: cmd_generator_execute
|
||||
name: 'generate'
|
||||
description: 'generator for vlang code in hero context.\narg is path (required). Use "." for current directory.'
|
||||
// required_args: 1
|
||||
execute: cmd_generator_execute
|
||||
}
|
||||
|
||||
cmd_run.add_flag(Flag{
|
||||
@@ -20,14 +20,6 @@ pub fn cmd_generator(mut cmdroot Command) {
|
||||
description: 'will reset.'
|
||||
})
|
||||
|
||||
cmd_run.add_flag(Flag{
|
||||
flag: .string
|
||||
required: false
|
||||
name: 'path'
|
||||
abbrev: 'p'
|
||||
description: 'path where to generate the code or scan over multiple directories.'
|
||||
})
|
||||
|
||||
cmd_run.add_flag(Flag{
|
||||
flag: .bool
|
||||
required: false
|
||||
@@ -48,7 +40,7 @@ pub fn cmd_generator(mut cmdroot Command) {
|
||||
required: false
|
||||
name: 'scan'
|
||||
abbrev: 's'
|
||||
description: 'force scanning operation.'
|
||||
description: 'scanning operation, walk over directories.'
|
||||
})
|
||||
|
||||
cmd_run.add_flag(Flag{
|
||||
@@ -68,17 +60,30 @@ fn cmd_generator_execute(cmd Command) ! {
|
||||
mut scan := cmd.flags.get_bool('scan') or { false }
|
||||
mut playonly := cmd.flags.get_bool('playonly') or { false }
|
||||
mut installer := cmd.flags.get_bool('installer') or { false }
|
||||
mut path := cmd.flags.get_string('path') or { '' }
|
||||
|
||||
// Get path from required argument
|
||||
mut path := ''
|
||||
|
||||
if cmd.args.len > 0 {
|
||||
path = cmd.args[0]
|
||||
}
|
||||
|
||||
if playonly {
|
||||
force = true
|
||||
}
|
||||
|
||||
if path == '' {
|
||||
// Handle "." as current working directory
|
||||
if path == '.' {
|
||||
path = os.getwd()
|
||||
}
|
||||
} else {
|
||||
// Expand home directory
|
||||
path = path.replace('~', os.home_dir())
|
||||
|
||||
path = path.replace('~', os.home_dir())
|
||||
// Validate that path exists
|
||||
if !os.exists(path) {
|
||||
return error('Path does not exist: ${path}')
|
||||
}
|
||||
}
|
||||
|
||||
mut cat := generic.Cat.client
|
||||
if installer {
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
module herocmds
|
||||
|
||||
import cli { Command }
|
||||
|
||||
// path string //if location on filessytem, if exists, this has prio on git_url
|
||||
// git_url string // location of where the hero scripts are
|
||||
// git_pull bool // means when getting new repo will pull even when repo is already there
|
||||
// git_pullreset bool // means we will force a pull and reset old content
|
||||
// coderoot string //the location of coderoot if its another one
|
||||
pub fn cmd_run(mut cmdroot Command) {
|
||||
mut cmd_run := Command{
|
||||
name: 'run'
|
||||
usage: '
|
||||
## Powerfull command to run heroscript
|
||||
|
||||
heroscript has numerous ways to execute actions using your hero tool.
|
||||
|
||||
example:
|
||||
|
||||
hero run -u https://git.threefold.info/threefold_coop/info_asimov/src/branch/main/heroscript
|
||||
|
||||
Can also do -e or -st to see sourcetree
|
||||
|
||||
If you do -gp it will pull newest heroscripts from git and give error if there are local changes.
|
||||
If you do -gr it will pull newest heroscripts from git and overwrite local changes (careful).
|
||||
|
||||
|
||||
'
|
||||
required_args: 0
|
||||
description: 'run heroscript commands'
|
||||
execute: cmd_heroscript_execute
|
||||
}
|
||||
cmd_run_add_flags(mut cmd_run)
|
||||
|
||||
cmdroot.add_command(cmd_run)
|
||||
}
|
||||
|
||||
fn cmd_heroscript_execute(cmd Command) ! {
|
||||
plbook_edit_sourcetree(cmd)!
|
||||
}
|
||||
@@ -2,7 +2,7 @@ module gittools
|
||||
|
||||
pub fn (mut repo GitRepo) check() ! {
|
||||
repo.init()!
|
||||
if repo.lfs()! {
|
||||
repo.lfs_check()!
|
||||
}
|
||||
// if repo.lfs()! {
|
||||
// repo.lfs_check()!
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -16,15 +16,13 @@ __global (
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
path string
|
||||
fromdb bool // will load from filesystem
|
||||
create bool // default will not create if not exist
|
||||
}
|
||||
|
||||
pub fn new(args ArgsGet) !&Workspace {
|
||||
mut obj := Workspace{
|
||||
name: args.name
|
||||
base_path: args.path
|
||||
name: args.name
|
||||
}
|
||||
set(obj)!
|
||||
return get(name: args.name)!
|
||||
@@ -38,6 +36,7 @@ pub fn get(args ArgsGet) !&Workspace {
|
||||
if r.hexists('context:heroprompt', args.name)! {
|
||||
data := r.hget('context:heroprompt', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('Workspace with name: heroprompt does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(Workspace, data)!
|
||||
@@ -46,12 +45,14 @@ pub fn get(args ArgsGet) !&Workspace {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("Workspace with name 'heroprompt' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return heroprompt_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for heroprompt with name:heroprompt')
|
||||
}
|
||||
}
|
||||
@@ -122,28 +123,14 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
if !plbook.exists(filter: 'heroprompt.') {
|
||||
return
|
||||
}
|
||||
// 1) Configure workspaces
|
||||
mut cfg_actions := plbook.find(filter: 'heroprompt.configure')!
|
||||
for cfg_action in cfg_actions {
|
||||
heroscript := cfg_action.heroscript()
|
||||
mut obj := heroscript_loads(heroscript)!
|
||||
set(obj)!
|
||||
}
|
||||
// 2) Add directories
|
||||
for action in plbook.find(filter: 'heroprompt.add_dir')! {
|
||||
mut p := action.params
|
||||
wsname := p.get_default('name', heroprompt_default)!
|
||||
mut wsp := get(name: wsname)!
|
||||
path := p.get('path') or { return error("heroprompt.add_dir requires 'path'") }
|
||||
wsp.add_dir(path: path)!
|
||||
}
|
||||
// 3) Add files
|
||||
for action in plbook.find(filter: 'heroprompt.add_file')! {
|
||||
mut p := action.params
|
||||
wsname := p.get_default('name', heroprompt_default)!
|
||||
mut wsp := get(name: wsname)!
|
||||
path := p.get('path') or { return error("heroprompt.add_file requires 'path'") }
|
||||
wsp.add_file(path: path)!
|
||||
mut install_actions := plbook.find(filter: 'heroprompt.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
return error("can't configure herorunner, because no configuration allowed for this installer.")
|
||||
}
|
||||
mut other_actions := plbook.find(filter: 'herorunner.')!
|
||||
for other_action in other_actions {
|
||||
for mut other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
mut p := other_action.params
|
||||
reset := p.get_default_false('reset')
|
||||
@@ -48,6 +48,7 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
other_action.done = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ module deployer
|
||||
import incubaid.herolib.core.base
|
||||
import incubaid.herolib.core.playbook { PlayBook }
|
||||
import incubaid.herolib.ui.console
|
||||
import json
|
||||
|
||||
__global (
|
||||
deployer_global map[string]&TFGridDeployer
|
||||
@@ -14,77 +15,121 @@ __global (
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
name string = 'default'
|
||||
fromdb bool // will load from filesystem
|
||||
create bool // default will not create if not exist
|
||||
}
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&TFGridDeployer {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
pub fn new(args ArgsGet) !&TFGridDeployer {
|
||||
mut obj := TFGridDeployer{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in deployer_global {
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
set(obj)!
|
||||
return get(name: args.name)!
|
||||
}
|
||||
|
||||
pub fn get(args ArgsGet) !&TFGridDeployer {
|
||||
mut context := base.context()!
|
||||
deployer_default = args.name
|
||||
if args.fromdb || args.name !in deployer_global {
|
||||
mut r := context.redis()!
|
||||
if r.hexists('context:deployer', args.name)! {
|
||||
data := r.hget('context:deployer', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('TFGridDeployer with name: deployer does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(TFGridDeployer, data)!
|
||||
set_in_mem(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('deployer', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("TFGridDeployer with name 'deployer' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return deployer_global[args.name] or {
|
||||
println(deployer_global)
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for deployer with name, is bug:${args.name}')
|
||||
print_backtrace()
|
||||
return error('could not get config for deployer with name:deployer')
|
||||
}
|
||||
}
|
||||
|
||||
// register the config for the future
|
||||
pub fn set(o TFGridDeployer) ! {
|
||||
set_in_mem(o)!
|
||||
mut o2 := set_in_mem(o)!
|
||||
deployer_default = o2.name
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('deployer', o.name, heroscript)!
|
||||
mut r := context.redis()!
|
||||
r.hset('context:deployer', o2.name, json.encode(o2))!
|
||||
}
|
||||
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
pub fn exists(args ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists('deployer', args.name)
|
||||
mut r := context.redis()!
|
||||
return r.hexists('context:deployer', args.name)!
|
||||
}
|
||||
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
pub fn delete(args ArgsGet) ! {
|
||||
mut context := base.context()!
|
||||
context.hero_config_delete('deployer', args.name)!
|
||||
if args.name in deployer_global {
|
||||
// del deployer_global[args.name]
|
||||
mut r := context.redis()!
|
||||
r.hdel('context:deployer', args.name)!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct ArgsList {
|
||||
pub mut:
|
||||
fromdb bool // will load from filesystem
|
||||
}
|
||||
|
||||
// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem
|
||||
pub fn list(args ArgsList) ![]&TFGridDeployer {
|
||||
mut res := []&TFGridDeployer{}
|
||||
mut context := base.context()!
|
||||
if args.fromdb {
|
||||
// reset what is in mem
|
||||
deployer_global = map[string]&TFGridDeployer{}
|
||||
deployer_default = ''
|
||||
}
|
||||
if args.fromdb {
|
||||
mut r := context.redis()!
|
||||
mut l := r.hkeys('context:deployer')!
|
||||
|
||||
for name in l {
|
||||
res << get(name: name, fromdb: true)!
|
||||
}
|
||||
return res
|
||||
} else {
|
||||
// load from memory
|
||||
for _, client in deployer_global {
|
||||
res << client
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o TFGridDeployer) ! {
|
||||
fn set_in_mem(o TFGridDeployer) !TFGridDeployer {
|
||||
mut o2 := obj_init(o)!
|
||||
deployer_global[o.name] = &o2
|
||||
deployer_default = o.name
|
||||
deployer_global[o2.name] = &o2
|
||||
deployer_default = o2.name
|
||||
return o2
|
||||
}
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
if !plbook.exists(filter: 'deployer.') {
|
||||
return
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'deployer.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
for mut install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
install_action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,10 +138,3 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
pub fn switch(name string) {
|
||||
deployer_default = name
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&HetznerManager {
|
||||
if r.hexists('context:hetznermanager', args.name)! {
|
||||
data := r.hget('context:hetznermanager', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('HetznerManager with name: hetznermanager does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(HetznerManager, data)!
|
||||
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&HetznerManager {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("HetznerManager with name 'hetznermanager' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
}
|
||||
return hetznermanager_global[args.name] or {
|
||||
print_backtrace()
|
||||
return error('could not get config for hetznermanager with name:hetznermanager')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user