This commit is contained in:
2025-10-13 08:30:42 +04:00
parent cf304e004e
commit b154a91867
31 changed files with 242 additions and 242 deletions

View File

@@ -38,6 +38,10 @@ fn do() ! {
if os.args.len == 2 { if os.args.len == 2 {
mypath := os.args[1] mypath := os.args[1]
if mypath == '.' {
playcmds_do(os.getwd())!
return
}
if mypath.to_lower().ends_with('.hero') || mypath.to_lower().ends_with('.heroscript') if mypath.to_lower().ends_with('.hero') || mypath.to_lower().ends_with('.heroscript')
|| mypath.to_lower().ends_with('.hs') { || mypath.to_lower().ends_with('.hs') {
// hero was called from a file // hero was called from a file
@@ -82,7 +86,6 @@ fn do() ! {
base.redis_install()! base.redis_install()!
herocmds.cmd_run(mut cmd)
herocmds.cmd_git(mut cmd) herocmds.cmd_git(mut cmd)
herocmds.cmd_generator(mut cmd) herocmds.cmd_generator(mut cmd)
herocmds.cmd_docusaurus(mut cmd) herocmds.cmd_docusaurus(mut cmd)
@@ -101,7 +104,3 @@ fn main() {
exit(1) exit(1)
} }
} }
// fn pre_func(cmd Command) ! {
// herocmds.plbook_run(cmd)!
// }

View File

@@ -1,2 +1 @@
!!git.check !!git.check filter:'herolib'
filter: 'test_repo'

View File

@@ -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')

View File

@@ -445,6 +445,16 @@ check_and_start_redis() {
return return
fi 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 if systemctl is-active --quiet "redis"; then
echo "redis is already running." echo "redis is already running."
else else
@@ -631,7 +641,7 @@ if [ "$RESET" = true ] || ! command_exists v; then
fi fi
# set -x
check_and_start_redis check_and_start_redis
if [ "$HEROLIB" = true ]; then if [ "$HEROLIB" = true ]; then

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&GiteaClient {
if r.hexists('context:giteaclient', args.name)! { if r.hexists('context:giteaclient', args.name)! {
data := r.hget('context:giteaclient', args.name)! data := r.hget('context:giteaclient', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('GiteaClient with name: giteaclient does not exist, prob bug.') return error('GiteaClient with name: giteaclient does not exist, prob bug.')
} }
mut obj := json.decode(GiteaClient, data)! mut obj := json.decode(GiteaClient, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&GiteaClient {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("GiteaClient with name 'giteaclient' does not exist") return error("GiteaClient with name 'giteaclient' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return giteaclient_global[args.name] or { return giteaclient_global[args.name] or {
print_backtrace()
return error('could not get config for giteaclient with name:giteaclient') 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')! mut install_actions := plbook.find(filter: 'giteaclient.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&IPApi {
if r.hexists('context:ipapi', args.name)! { if r.hexists('context:ipapi', args.name)! {
data := r.hget('context:ipapi', args.name)! data := r.hget('context:ipapi', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('IPApi with name: ipapi does not exist, prob bug.') return error('IPApi with name: ipapi does not exist, prob bug.')
} }
mut obj := json.decode(IPApi, data)! mut obj := json.decode(IPApi, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&IPApi {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("IPApi with name 'ipapi' does not exist") return error("IPApi with name 'ipapi' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return ipapi_global[args.name] or { return ipapi_global[args.name] or {
print_backtrace()
return error('could not get config for ipapi with name:ipapi') 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')! mut install_actions := plbook.find(filter: 'ipapi.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&Jina {
if r.hexists('context:jina', args.name)! { if r.hexists('context:jina', args.name)! {
data := r.hget('context:jina', args.name)! data := r.hget('context:jina', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('Jina with name: jina does not exist, prob bug.') return error('Jina with name: jina does not exist, prob bug.')
} }
mut obj := json.decode(Jina, data)! mut obj := json.decode(Jina, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&Jina {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("Jina with name 'jina' does not exist") return error("Jina with name 'jina' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return jina_global[args.name] or { return jina_global[args.name] or {
print_backtrace()
return error('could not get config for jina with name:jina') 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')! mut install_actions := plbook.find(filter: 'jina.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&LivekitClient {
if r.hexists('context:livekit', args.name)! { if r.hexists('context:livekit', args.name)! {
data := r.hget('context:livekit', args.name)! data := r.hget('context:livekit', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('LivekitClient with name: livekit does not exist, prob bug.') return error('LivekitClient with name: livekit does not exist, prob bug.')
} }
mut obj := json.decode(LivekitClient, data)! mut obj := json.decode(LivekitClient, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&LivekitClient {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("LivekitClient with name 'livekit' does not exist") return error("LivekitClient with name 'livekit' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return livekit_global[args.name] or { return livekit_global[args.name] or {
print_backtrace()
return error('could not get config for livekit with name:livekit') 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')! mut install_actions := plbook.find(filter: 'livekit.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&MailClient {
if r.hexists('context:mailclient', args.name)! { if r.hexists('context:mailclient', args.name)! {
data := r.hget('context:mailclient', args.name)! data := r.hget('context:mailclient', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('MailClient with name: mailclient does not exist, prob bug.') return error('MailClient with name: mailclient does not exist, prob bug.')
} }
mut obj := json.decode(MailClient, data)! mut obj := json.decode(MailClient, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&MailClient {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("MailClient with name 'mailclient' does not exist") return error("MailClient with name 'mailclient' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return mailclient_global[args.name] or { return mailclient_global[args.name] or {
print_backtrace()
return error('could not get config for mailclient with name:mailclient') 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')! mut install_actions := plbook.find(filter: 'mailclient.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&MeilisearchClient {
if r.hexists('context:meilisearch', args.name)! { if r.hexists('context:meilisearch', args.name)! {
data := r.hget('context:meilisearch', args.name)! data := r.hget('context:meilisearch', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('MeilisearchClient with name: meilisearch does not exist, prob bug.') return error('MeilisearchClient with name: meilisearch does not exist, prob bug.')
} }
mut obj := json.decode(MeilisearchClient, data)! mut obj := json.decode(MeilisearchClient, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&MeilisearchClient {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("MeilisearchClient with name 'meilisearch' does not exist") return error("MeilisearchClient with name 'meilisearch' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return meilisearch_global[args.name] or { return meilisearch_global[args.name] or {
print_backtrace()
return error('could not get config for meilisearch with name:meilisearch') 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')! mut install_actions := plbook.find(filter: 'meilisearch.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -2,6 +2,7 @@ module mycelium
import incubaid.herolib.core.base import incubaid.herolib.core.base
import incubaid.herolib.core.playbook { PlayBook } import incubaid.herolib.core.playbook { PlayBook }
import incubaid.herolib.ui.console
import json import json
__global ( __global (
@@ -35,6 +36,7 @@ pub fn get(args ArgsGet) !&Mycelium {
if r.hexists('context:mycelium', args.name)! { if r.hexists('context:mycelium', args.name)! {
data := r.hget('context:mycelium', args.name)! data := r.hget('context:mycelium', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('Mycelium with name: mycelium does not exist, prob bug.') return error('Mycelium with name: mycelium does not exist, prob bug.')
} }
mut obj := json.decode(Mycelium, data)! mut obj := json.decode(Mycelium, data)!
@@ -43,12 +45,14 @@ pub fn get(args ArgsGet) !&Mycelium {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("Mycelium with name 'mycelium' does not exist") return error("Mycelium with name 'mycelium' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return mycelium_global[args.name] or { return mycelium_global[args.name] or {
print_backtrace()
return error('could not get config for mycelium with name:mycelium') 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')! mut install_actions := plbook.find(filter: 'mycelium.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&MyceliumRPC {
if r.hexists('context:mycelium_rpc', args.name)! { if r.hexists('context:mycelium_rpc', args.name)! {
data := r.hget('context:mycelium_rpc', args.name)! data := r.hget('context:mycelium_rpc', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('MyceliumRPC with name: mycelium_rpc does not exist, prob bug.') return error('MyceliumRPC with name: mycelium_rpc does not exist, prob bug.')
} }
mut obj := json.decode(MyceliumRPC, data)! mut obj := json.decode(MyceliumRPC, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&MyceliumRPC {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("MyceliumRPC with name 'mycelium_rpc' does not exist") return error("MyceliumRPC with name 'mycelium_rpc' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return mycelium_rpc_global[args.name] or { return mycelium_rpc_global[args.name] or {
print_backtrace()
return error('could not get config for mycelium_rpc with name:mycelium_rpc') 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')! mut install_actions := plbook.find(filter: 'mycelium_rpc.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&OpenAI {
if r.hexists('context:openai', args.name)! { if r.hexists('context:openai', args.name)! {
data := r.hget('context:openai', args.name)! data := r.hget('context:openai', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('OpenAI with name: openai does not exist, prob bug.') return error('OpenAI with name: openai does not exist, prob bug.')
} }
mut obj := json.decode(OpenAI, data)! mut obj := json.decode(OpenAI, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&OpenAI {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("OpenAI with name 'openai' does not exist") return error("OpenAI with name 'openai' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return openai_global[args.name] or { return openai_global[args.name] or {
print_backtrace()
return error('could not get config for openai with name:openai') 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')! mut install_actions := plbook.find(filter: 'openai.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&PostgresqlClient {
if r.hexists('context:postgresql_client', args.name)! { if r.hexists('context:postgresql_client', args.name)! {
data := r.hget('context:postgresql_client', args.name)! data := r.hget('context:postgresql_client', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('PostgresqlClient with name: postgresql_client does not exist, prob bug.') return error('PostgresqlClient with name: postgresql_client does not exist, prob bug.')
} }
mut obj := json.decode(PostgresqlClient, data)! mut obj := json.decode(PostgresqlClient, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&PostgresqlClient {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("PostgresqlClient with name 'postgresql_client' does not exist") return error("PostgresqlClient with name 'postgresql_client' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return postgresql_client_global[args.name] or { return postgresql_client_global[args.name] or {
print_backtrace()
return error('could not get config for postgresql_client with name:postgresql_client') 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')! mut install_actions := plbook.find(filter: 'postgresql_client.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&QDrantClient {
if r.hexists('context:qdrant', args.name)! { if r.hexists('context:qdrant', args.name)! {
data := r.hget('context:qdrant', args.name)! data := r.hget('context:qdrant', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('QDrantClient with name: qdrant does not exist, prob bug.') return error('QDrantClient with name: qdrant does not exist, prob bug.')
} }
mut obj := json.decode(QDrantClient, data)! mut obj := json.decode(QDrantClient, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&QDrantClient {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("QDrantClient with name 'qdrant' does not exist") return error("QDrantClient with name 'qdrant' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return qdrant_global[args.name] or { return qdrant_global[args.name] or {
print_backtrace()
return error('could not get config for qdrant with name:qdrant') 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')! mut install_actions := plbook.find(filter: 'qdrant.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&RCloneClient {
if r.hexists('context:rclone', args.name)! { if r.hexists('context:rclone', args.name)! {
data := r.hget('context:rclone', args.name)! data := r.hget('context:rclone', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('RCloneClient with name: rclone does not exist, prob bug.') return error('RCloneClient with name: rclone does not exist, prob bug.')
} }
mut obj := json.decode(RCloneClient, data)! mut obj := json.decode(RCloneClient, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&RCloneClient {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("RCloneClient with name 'rclone' does not exist") return error("RCloneClient with name 'rclone' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return rclone_global[args.name] or { return rclone_global[args.name] or {
print_backtrace()
return error('could not get config for rclone with name:rclone') 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')! mut install_actions := plbook.find(filter: 'rclone.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&RunPod {
if r.hexists('context:runpod', args.name)! { if r.hexists('context:runpod', args.name)! {
data := r.hget('context:runpod', args.name)! data := r.hget('context:runpod', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('RunPod with name: runpod does not exist, prob bug.') return error('RunPod with name: runpod does not exist, prob bug.')
} }
mut obj := json.decode(RunPod, data)! mut obj := json.decode(RunPod, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&RunPod {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("RunPod with name 'runpod' does not exist") return error("RunPod with name 'runpod' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return runpod_global[args.name] or { return runpod_global[args.name] or {
print_backtrace()
return error('could not get config for runpod with name:runpod') 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')! mut install_actions := plbook.find(filter: 'runpod.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&SendGrid {
if r.hexists('context:sendgrid', args.name)! { if r.hexists('context:sendgrid', args.name)! {
data := r.hget('context:sendgrid', args.name)! data := r.hget('context:sendgrid', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('SendGrid with name: sendgrid does not exist, prob bug.') return error('SendGrid with name: sendgrid does not exist, prob bug.')
} }
mut obj := json.decode(SendGrid, data)! mut obj := json.decode(SendGrid, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&SendGrid {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("SendGrid with name 'sendgrid' does not exist") return error("SendGrid with name 'sendgrid' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return sendgrid_global[args.name] or { return sendgrid_global[args.name] or {
print_backtrace()
return error('could not get config for sendgrid with name:sendgrid') 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')! mut install_actions := plbook.find(filter: 'sendgrid.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&VastAI {
if r.hexists('context:vastai', args.name)! { if r.hexists('context:vastai', args.name)! {
data := r.hget('context:vastai', args.name)! data := r.hget('context:vastai', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('VastAI with name: vastai does not exist, prob bug.') return error('VastAI with name: vastai does not exist, prob bug.')
} }
mut obj := json.decode(VastAI, data)! mut obj := json.decode(VastAI, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&VastAI {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("VastAI with name 'vastai' does not exist") return error("VastAI with name 'vastai' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return vastai_global[args.name] or { return vastai_global[args.name] or {
print_backtrace()
return error('could not get config for vastai with name:vastai') 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')! mut install_actions := plbook.find(filter: 'vastai.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&WireGuard {
if r.hexists('context:wireguard', args.name)! { if r.hexists('context:wireguard', args.name)! {
data := r.hget('context:wireguard', args.name)! data := r.hget('context:wireguard', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('WireGuard with name: wireguard does not exist, prob bug.') return error('WireGuard with name: wireguard does not exist, prob bug.')
} }
mut obj := json.decode(WireGuard, data)! mut obj := json.decode(WireGuard, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&WireGuard {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("WireGuard with name 'wireguard' does not exist") return error("WireGuard with name 'wireguard' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return wireguard_global[args.name] or { return wireguard_global[args.name] or {
print_backtrace()
return error('could not get config for wireguard with name:wireguard') 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')! mut install_actions := plbook.find(filter: 'wireguard.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&ZeroDBClient {
if r.hexists('context:zerodb_client', args.name)! { if r.hexists('context:zerodb_client', args.name)! {
data := r.hget('context:zerodb_client', args.name)! data := r.hget('context:zerodb_client', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('ZeroDBClient with name: zerodb_client does not exist, prob bug.') return error('ZeroDBClient with name: zerodb_client does not exist, prob bug.')
} }
mut obj := json.decode(ZeroDBClient, data)! mut obj := json.decode(ZeroDBClient, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&ZeroDBClient {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("ZeroDBClient with name 'zerodb_client' does not exist") return error("ZeroDBClient with name 'zerodb_client' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return zerodb_client_global[args.name] or { return zerodb_client_global[args.name] or {
print_backtrace()
return error('could not get config for zerodb_client with name:zerodb_client') 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')! mut install_actions := plbook.find(filter: 'zerodb_client.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&ZinitRPC {
if r.hexists('context:zinit', args.name)! { if r.hexists('context:zinit', args.name)! {
data := r.hget('context:zinit', args.name)! data := r.hget('context:zinit', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('ZinitRPC with name: zinit does not exist, prob bug.') return error('ZinitRPC with name: zinit does not exist, prob bug.')
} }
mut obj := json.decode(ZinitRPC, data)! mut obj := json.decode(ZinitRPC, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&ZinitRPC {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("ZinitRPC with name 'zinit' does not exist") return error("ZinitRPC with name 'zinit' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return zinit_global[args.name] or { return zinit_global[args.name] or {
print_backtrace()
return error('could not get config for zinit with name:zinit') 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')! mut install_actions := plbook.find(filter: 'zinit.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }

View File

@@ -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_header('Generate code for path: ${args.path} (reset:${args.force}, force:${args.force})')
console.print_debug(args) console.print_debug(args)
if args.path == '' { if args.path == '' {
args.path = os.getwd() return error('no path provided')
} }
if args.name == '' { if args.name == '' {

View File

@@ -21,10 +21,19 @@ pub fn scan(args_ GeneratorArgs) ! {
regex: ['.heroscript'] regex: ['.heroscript']
)! )!
console.print_debug('Found ${plist.paths.len} directories with .heroscript file.')
for mut p in plist.paths { for mut p in plist.paths {
pparent := p.parent()! pparent := p.parent()!
args.force = true
args.path = pparent.path args.path = pparent.path
// println("-- ${pparent}")
generate(args)! 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;
} }

View File

@@ -7,8 +7,8 @@ import cli { Command, Flag }
pub fn cmd_generator(mut cmdroot Command) { pub fn cmd_generator(mut cmdroot Command) {
mut cmd_run := Command{ mut cmd_run := Command{
name: 'generate' name: 'generate'
description: 'generator for vlang code in hero context.' description: 'generator for vlang code in hero context.\narg is path (required). Use "." for current directory.'
required_args: 0 // required_args: 1
execute: cmd_generator_execute execute: cmd_generator_execute
} }
@@ -20,14 +20,6 @@ pub fn cmd_generator(mut cmdroot Command) {
description: 'will reset.' 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{ cmd_run.add_flag(Flag{
flag: .bool flag: .bool
required: false required: false
@@ -48,7 +40,7 @@ pub fn cmd_generator(mut cmdroot Command) {
required: false required: false
name: 'scan' name: 'scan'
abbrev: 's' abbrev: 's'
description: 'force scanning operation.' description: 'scanning operation, walk over directories.'
}) })
cmd_run.add_flag(Flag{ cmd_run.add_flag(Flag{
@@ -68,18 +60,31 @@ fn cmd_generator_execute(cmd Command) ! {
mut scan := cmd.flags.get_bool('scan') or { false } mut scan := cmd.flags.get_bool('scan') or { false }
mut playonly := cmd.flags.get_bool('playonly') or { false } mut playonly := cmd.flags.get_bool('playonly') or { false }
mut installer := cmd.flags.get_bool('installer') 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 { if playonly {
force = true force = true
} }
if path == '' { // Handle "." as current working directory
if path == '.' {
path = os.getwd() 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 mut cat := generic.Cat.client
if installer { if installer {
cat = generic.Cat.installer cat = generic.Cat.installer

View File

@@ -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)!
}

View File

@@ -2,7 +2,7 @@ module gittools
pub fn (mut repo GitRepo) check() ! { pub fn (mut repo GitRepo) check() ! {
repo.init()! repo.init()!
if repo.lfs()! { // if repo.lfs()! {
repo.lfs_check()! // repo.lfs_check()!
} // }
} }

View File

@@ -16,7 +16,6 @@ __global (
pub struct ArgsGet { pub struct ArgsGet {
pub mut: pub mut:
name string = 'default' name string = 'default'
path string
fromdb bool // will load from filesystem fromdb bool // will load from filesystem
create bool // default will not create if not exist create bool // default will not create if not exist
} }
@@ -24,7 +23,6 @@ pub mut:
pub fn new(args ArgsGet) !&Workspace { pub fn new(args ArgsGet) !&Workspace {
mut obj := Workspace{ mut obj := Workspace{
name: args.name name: args.name
base_path: args.path
} }
set(obj)! set(obj)!
return get(name: args.name)! return get(name: args.name)!
@@ -38,6 +36,7 @@ pub fn get(args ArgsGet) !&Workspace {
if r.hexists('context:heroprompt', args.name)! { if r.hexists('context:heroprompt', args.name)! {
data := r.hget('context:heroprompt', args.name)! data := r.hget('context:heroprompt', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('Workspace with name: heroprompt does not exist, prob bug.') return error('Workspace with name: heroprompt does not exist, prob bug.')
} }
mut obj := json.decode(Workspace, data)! mut obj := json.decode(Workspace, data)!
@@ -46,12 +45,14 @@ pub fn get(args ArgsGet) !&Workspace {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("Workspace with name 'heroprompt' does not exist") return error("Workspace with name 'heroprompt' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return heroprompt_global[args.name] or { return heroprompt_global[args.name] or {
print_backtrace()
return error('could not get config for heroprompt with name:heroprompt') 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.') { if !plbook.exists(filter: 'heroprompt.') {
return return
} }
// 1) Configure workspaces mut install_actions := plbook.find(filter: 'heroprompt.configure')!
mut cfg_actions := plbook.find(filter: 'heroprompt.configure')! if install_actions.len > 0 {
for cfg_action in cfg_actions { for mut install_action in install_actions {
heroscript := cfg_action.heroscript() heroscript := install_action.heroscript()
mut obj := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj)! set(obj2)!
install_action.done = true
} }
// 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)!
} }
} }

View File

@@ -35,7 +35,7 @@ pub fn play(mut plbook PlayBook) ! {
return error("can't configure herorunner, because no configuration allowed for this installer.") return error("can't configure herorunner, because no configuration allowed for this installer.")
} }
mut other_actions := plbook.find(filter: 'herorunner.')! 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'] { if other_action.name in ['destroy', 'install', 'build'] {
mut p := other_action.params mut p := other_action.params
reset := p.get_default_false('reset') reset := p.get_default_false('reset')
@@ -48,6 +48,7 @@ pub fn play(mut plbook PlayBook) ! {
install()! install()!
} }
} }
other_action.done = true
} }
} }

View File

@@ -3,6 +3,7 @@ module deployer
import incubaid.herolib.core.base import incubaid.herolib.core.base
import incubaid.herolib.core.playbook { PlayBook } import incubaid.herolib.core.playbook { PlayBook }
import incubaid.herolib.ui.console import incubaid.herolib.ui.console
import json
__global ( __global (
deployer_global map[string]&TFGridDeployer deployer_global map[string]&TFGridDeployer
@@ -14,77 +15,121 @@ __global (
@[params] @[params]
pub struct ArgsGet { pub struct ArgsGet {
pub mut: 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 { pub fn new(args ArgsGet) !&TFGridDeployer {
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_)
mut obj := TFGridDeployer{ mut obj := TFGridDeployer{
name: args.name name: args.name
} }
if args.name !in deployer_global {
if !exists(args)! {
set(obj)! set(obj)!
} else { return get(name: args.name)!
heroscript := context.hero_config_get('deployer', args.name)!
mut obj_ := heroscript_loads(heroscript)!
set_in_mem(obj_)!
} }
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 {
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 { return deployer_global[args.name] or {
println(deployer_global) print_backtrace()
// bug if we get here because should be in globals return error('could not get config for deployer with name:deployer')
panic('could not get config for deployer with name, is bug:${args.name}')
} }
} }
// register the config for the future // register the config for the future
pub fn set(o TFGridDeployer) ! { pub fn set(o TFGridDeployer) ! {
set_in_mem(o)! mut o2 := set_in_mem(o)!
deployer_default = o2.name
mut context := base.context()! mut context := base.context()!
heroscript := heroscript_dumps(o)! mut r := context.redis()!
context.hero_config_set('deployer', o.name, heroscript)! r.hset('context:deployer', o2.name, json.encode(o2))!
} }
// does the config exists? // does the config exists?
pub fn exists(args_ ArgsGet) !bool { pub fn exists(args ArgsGet) !bool {
mut context := base.context()! mut context := base.context()!
mut args := args_get(args_) mut r := context.redis()!
return context.hero_config_exists('deployer', args.name) return r.hexists('context:deployer', args.name)!
} }
pub fn delete(args_ ArgsGet) ! { pub fn delete(args ArgsGet) ! {
mut args := args_get(args_)
mut context := base.context()! mut context := base.context()!
context.hero_config_delete('deployer', args.name)! mut r := context.redis()!
if args.name in deployer_global { r.hdel('context:deployer', args.name)!
// del deployer_global[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 // 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)! mut o2 := obj_init(o)!
deployer_global[o.name] = &o2 deployer_global[o2.name] = &o2
deployer_default = o.name deployer_default = o2.name
return o2
} }
pub fn play(mut plbook PlayBook) ! { pub fn play(mut plbook PlayBook) ! {
if !plbook.exists(filter: 'deployer.') {
return
}
mut install_actions := plbook.find(filter: 'deployer.configure')! mut install_actions := plbook.find(filter: 'deployer.configure')!
if install_actions.len > 0 { if install_actions.len > 0 {
for install_action in install_actions { for mut install_action in install_actions {
heroscript := install_action.heroscript() heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)! mut obj2 := heroscript_loads(heroscript)!
set(obj2)! set(obj2)!
install_action.done = true
} }
} }
} }
@@ -93,10 +138,3 @@ pub fn play(mut plbook PlayBook) ! {
pub fn switch(name string) { pub fn switch(name string) {
deployer_default = name deployer_default = name
} }
// helpers
@[params]
pub struct DefaultConfigArgs {
instance string = 'default'
}

View File

@@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&HetznerManager {
if r.hexists('context:hetznermanager', args.name)! { if r.hexists('context:hetznermanager', args.name)! {
data := r.hget('context:hetznermanager', args.name)! data := r.hget('context:hetznermanager', args.name)!
if data.len == 0 { if data.len == 0 {
print_backtrace()
return error('HetznerManager with name: hetznermanager does not exist, prob bug.') return error('HetznerManager with name: hetznermanager does not exist, prob bug.')
} }
mut obj := json.decode(HetznerManager, data)! mut obj := json.decode(HetznerManager, data)!
@@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&HetznerManager {
if args.create { if args.create {
new(args)! new(args)!
} else { } else {
print_backtrace()
return error("HetznerManager with name 'hetznermanager' does not exist") return error("HetznerManager with name 'hetznermanager' does not exist")
} }
} }
return get(name: args.name)! // no longer from db nor create return get(name: args.name)! // no longer from db nor create
} }
return hetznermanager_global[args.name] or { return hetznermanager_global[args.name] or {
print_backtrace()
return error('could not get config for hetznermanager with name:hetznermanager') return error('could not get config for hetznermanager with name:hetznermanager')
} }
} }