Module: BrainzLab::Synapse
- Defined in:
- lib/brainzlab/synapse.rb,
lib/brainzlab/synapse/client.rb,
lib/brainzlab/synapse/provisioner.rb
Defined Under Namespace
Classes: Client, Provisioner
Class Method Summary collapse
-
.cancel_task(task_id) ⇒ Boolean
Cancel a running task.
- .client ⇒ Object
-
.create_project(name:, repos: [], description: nil) ⇒ Hash?
Create a new project.
-
.deploy(project_id, environment:, **options) ⇒ Hash?
Deploy project to environment.
-
.deployment(deployment_id) ⇒ Hash?
Get deployment status.
-
.down(project_id) ⇒ Boolean
Stop project containers.
-
.ensure_provisioned! ⇒ Object
INTERNAL ===.
-
.exec(project_id, command:, container: nil, timeout: 30) ⇒ Hash?
Execute command in container.
-
.get_task(task_id) ⇒ Hash?
Get task details.
-
.logs(project_id, container: nil, lines: 100, since: nil) ⇒ Hash?
Get container logs.
-
.project(project_id) ⇒ Hash?
Get project details.
-
.projects(status: nil, page: 1, per_page: 20) ⇒ Array<Hash>
List all projects.
- .provisioner ⇒ Object
- .reset! ⇒ Object
-
.restart(project_id) ⇒ Boolean
Restart project containers.
-
.task(project_id:, description:, type: nil, priority: nil) ⇒ Hash?
Create an AI development task.
-
.task_status(task_id) ⇒ Hash?
Get task status and progress.
-
.tasks(project_id: nil, status: nil, page: 1, per_page: 20) ⇒ Array<Hash>
List tasks.
-
.up(project_id) ⇒ Boolean
Start project containers.
Class Method Details
.cancel_task(task_id) ⇒ Boolean
Cancel a running task
197 198 199 200 201 202 203 204 |
# File 'lib/brainzlab/synapse.rb', line 197 def cancel_task(task_id) return false unless enabled? ensure_provisioned! return false unless BrainzLab.configuration.synapse_valid? client.cancel_task(task_id) end |
.client ⇒ Object
253 254 255 |
# File 'lib/brainzlab/synapse.rb', line 253 def client @client ||= Client.new(BrainzLab.configuration) end |
.create_project(name:, repos: [], description: nil) ⇒ Hash?
Create a new project
52 53 54 55 56 57 58 59 |
# File 'lib/brainzlab/synapse.rb', line 52 def create_project(name:, repos: [], description: nil, **) return nil unless enabled? ensure_provisioned! return nil unless BrainzLab.configuration.synapse_valid? client.create_project(name: name, repos: repos, description: description, **) end |
.deploy(project_id, environment:, **options) ⇒ Hash?
Deploy project to environment
106 107 108 109 110 111 112 113 |
# File 'lib/brainzlab/synapse.rb', line 106 def deploy(project_id, environment:, **) return nil unless enabled? ensure_provisioned! return nil unless BrainzLab.configuration.synapse_valid? client.deploy(project_id, environment: environment, options: ) end |
.deployment(deployment_id) ⇒ Hash?
Get deployment status
118 119 120 121 122 123 124 125 |
# File 'lib/brainzlab/synapse.rb', line 118 def deployment(deployment_id) return nil unless enabled? ensure_provisioned! return nil unless BrainzLab.configuration.synapse_valid? client.get_deployment(deployment_id) end |
.down(project_id) ⇒ Boolean
Stop project containers
76 77 78 79 80 81 82 83 |
# File 'lib/brainzlab/synapse.rb', line 76 def down(project_id) return false unless enabled? ensure_provisioned! return false unless BrainzLab.configuration.synapse_valid? client.stop_project(project_id) end |
.ensure_provisioned! ⇒ Object
INTERNAL ===
242 243 244 245 246 247 |
# File 'lib/brainzlab/synapse.rb', line 242 def ensure_provisioned! return if @provisioned @provisioned = true provisioner.ensure_project! end |
.exec(project_id, command:, container: nil, timeout: 30) ⇒ Hash?
Execute command in container
231 232 233 234 235 236 237 238 |
# File 'lib/brainzlab/synapse.rb', line 231 def exec(project_id, command:, container: nil, timeout: 30) return nil unless enabled? ensure_provisioned! return nil unless BrainzLab.configuration.synapse_valid? client.exec(project_id, command: command, container: container, timeout: timeout) end |
.get_task(task_id) ⇒ Hash?
Get task details
160 161 162 163 164 165 166 167 |
# File 'lib/brainzlab/synapse.rb', line 160 def get_task(task_id) return nil unless enabled? ensure_provisioned! return nil unless BrainzLab.configuration.synapse_valid? client.get_task(task_id) end |
.logs(project_id, container: nil, lines: 100, since: nil) ⇒ Hash?
Get container logs
212 213 214 215 216 217 218 219 |
# File 'lib/brainzlab/synapse.rb', line 212 def logs(project_id, container: nil, lines: 100, since: nil) return nil unless enabled? ensure_provisioned! return nil unless BrainzLab.configuration.synapse_valid? client.get_logs(project_id, container: container, lines: lines, since: since) end |
.project(project_id) ⇒ Hash?
Get project details
28 29 30 31 32 33 34 35 |
# File 'lib/brainzlab/synapse.rb', line 28 def project(project_id) return nil unless enabled? ensure_provisioned! return nil unless BrainzLab.configuration.synapse_valid? client.get_project(project_id) end |
.projects(status: nil, page: 1, per_page: 20) ⇒ Array<Hash>
List all projects
16 17 18 19 20 21 22 23 |
# File 'lib/brainzlab/synapse.rb', line 16 def projects(status: nil, page: 1, per_page: 20) return [] unless enabled? ensure_provisioned! return [] unless BrainzLab.configuration.synapse_valid? client.list_projects(status: status, page: page, per_page: per_page) end |
.provisioner ⇒ Object
249 250 251 |
# File 'lib/brainzlab/synapse.rb', line 249 def provisioner @provisioner ||= Provisioner.new(BrainzLab.configuration) end |
.reset! ⇒ Object
257 258 259 260 261 |
# File 'lib/brainzlab/synapse.rb', line 257 def reset! @client = nil @provisioner = nil @provisioned = false end |
.restart(project_id) ⇒ Boolean
Restart project containers
88 89 90 91 92 93 94 95 |
# File 'lib/brainzlab/synapse.rb', line 88 def restart(project_id) return false unless enabled? ensure_provisioned! return false unless BrainzLab.configuration.synapse_valid? client.restart_project(project_id) end |
.task(project_id:, description:, type: nil, priority: nil) ⇒ Hash?
Create an AI development task
142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/brainzlab/synapse.rb', line 142 def task(project_id:, description:, type: nil, priority: nil, **) return nil unless enabled? ensure_provisioned! return nil unless BrainzLab.configuration.synapse_valid? client.create_task( project_id: project_id, description: description, type: type, priority: priority, ** ) end |
.task_status(task_id) ⇒ Hash?
Get task status and progress
172 173 174 175 176 177 178 179 |
# File 'lib/brainzlab/synapse.rb', line 172 def task_status(task_id) return nil unless enabled? ensure_provisioned! return nil unless BrainzLab.configuration.synapse_valid? client.get_task_status(task_id) end |
.tasks(project_id: nil, status: nil, page: 1, per_page: 20) ⇒ Array<Hash>
List tasks
185 186 187 188 189 190 191 192 |
# File 'lib/brainzlab/synapse.rb', line 185 def tasks(project_id: nil, status: nil, page: 1, per_page: 20) return [] unless enabled? ensure_provisioned! return [] unless BrainzLab.configuration.synapse_valid? client.list_tasks(project_id: project_id, status: status, page: page, per_page: per_page) end |
.up(project_id) ⇒ Boolean
Start project containers
64 65 66 67 68 69 70 71 |
# File 'lib/brainzlab/synapse.rb', line 64 def up(project_id) return false unless enabled? ensure_provisioned! return false unless BrainzLab.configuration.synapse_valid? client.start_project(project_id) end |