A Julia SDK for the ColonyOS API, enabling development of ColonyOS applications and executors in Julia.
- Tutorial - Getting started guide with step-by-step examples
- API Reference - Complete API documentation
- ColonyOS Tutorials - Advanced tutorials and examples
using Pkg
Pkg.add(url="https://github.com/colonyos/Colonies.jl")Start a local ColonyOS environment using Docker Compose:
wget https://raw.githubusercontent.com/colonyos/colonies/main/docker-compose.env
source docker-compose.env
wget https://raw.githubusercontent.com/colonyos/colonies/main/docker-compose.yml
docker-compose up -dTo stop and clean up:
docker-compose down --volumesusing Colonies
# Load configuration from environment variables
client, colonyname, colony_prvkey, executorname, prvkey = Colonies.client()Submit a job to run in a Docker container:
using Colonies
client, colonyname, colony_prvkey, executorname, prvkey = Colonies.client()
conditions = Colonies.Conditions(
colonyname=colonyname,
executornames=String["dev-docker"],
executortype="container-executor",
walltime=60
)
kwargs = Dict{Any, Any}()
kwargs["cmd"] = "echo hello world"
kwargs["docker-image"] = "ubuntu:20.04"
funcspec = Colonies.FunctionSpec(
funcname="execute",
kwargs=kwargs,
maxretries=3,
maxexectime=55,
conditions=conditions,
label="myprocess",
fs=Colonies.Filesystem()
)
process = Colonies.submit(client, funcspec, prvkey)
println("Process submitted: ", process.processid)
# Wait for completion
Colonies.wait(client, process, 60, prvkey)
# Get logs
logs = Colonies.getlogs(client, colonyname, process.processid, 100, 0, prvkey)
for log in logs
print(log.message)
endCreate a custom executor that handles processes:
using Colonies
import Colonies.Crypto
using Random
client, colonyname, colony_prvkey, executorname, prvkey = Colonies.client()
# Register executor
name = randstring(12)
executor_prvkey = Crypto.prvkey()
executor = Colonies.Executor(Crypto.id(executor_prvkey), "helloworld-executor", name, colonyname)
executor = Colonies.addexecutor(client, executor, colony_prvkey)
Colonies.approveexecutor(client, colonyname, executor.executorname, colony_prvkey)
# Main loop
while true
try
process = Colonies.assign(client, colonyname, 10, executor_prvkey)
if process === nothing
continue
end
funcname = get(process.spec, "funcname", "")
if funcname == "helloworld"
Colonies.addlog(client, process.processid, "Julia says Hello World!\n", executor_prvkey)
Colonies.closeprocess(client, process.processid, executor_prvkey, ["Hello World!"])
else
Colonies.failprocess(client, process.processid, executor_prvkey, ["Invalid function"])
end
catch e
println(e)
end
endusing Colonies
client, colonyname, colony_prvkey, executorname, prvkey = Colonies.client()
conditions = Colonies.Conditions(
colonyname=colonyname,
executortype="helloworld-executor"
)
funcspec = Colonies.FunctionSpec(
funcname="helloworld",
maxretries=3,
maxexectime=55,
conditions=conditions,
label="helloworld-process"
)
process = Colonies.submit(client, funcspec, prvkey)
Colonies.wait(client, process, 60, prvkey)
logs = Colonies.getlogs(client, colonyname, process.processid, 100, 0, prvkey)
for log in logs
print(log.message)
endsource docker-compose.env
cd examples
julia container.jl
julia helloworld_executor.jl
julia helloworld.jladdcolony,getcolony,getcolonies,removecolony
addexecutor,approveexecutor,rejectexecutorgetexecutor,getexecutors,removeexecutoraddfunction
submit,assign,getprocess,getprocessescloseprocess,failprocess,removeprocess,removeallprocessesaddattribute,setoutput,addchild,wait
submitworkflow,getprocessgraph,getprocessgraphsremoveprocessgraph,removeallprocessgraphs
addlog,getlogschannelappend,channelread
addblueprintdefinition,getblueprintdefinition,getblueprintdefinitions,removeblueprintdefinitionaddblueprint,getblueprint,getblueprints,updateblueprint,removeblueprintupdateblueprintstatus,reconcileblueprint
getstats,getfunctions
See the API Reference for complete documentation.
The Colonies CLI can be downloaded from GitHub Releases.
sudo cp colonies /usr/local/bin
colonies --helpOn macOS, grant permission in System Settings > Privacy & Security after first run.
Use the CLI to interact with the server:
source docker-compose.env
colonies executor ls
colonies process ps
colonies log search --text "Hello" -d 30MIT