withruntime 0.27.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/withruntime/generated/apps.rb +192 -0
- data/lib/withruntime/generated/audit.rb +78 -0
- data/lib/withruntime/generated/browsers.rb +192 -0
- data/lib/withruntime/generated/builds.rb +192 -0
- data/lib/withruntime/generated/ci.rb +192 -0
- data/lib/withruntime/generated/containers.rb +192 -0
- data/lib/withruntime/generated/desktops.rb +192 -0
- data/lib/withruntime/generated/domains.rb +152 -0
- data/lib/withruntime/generated/egress_ips.rb +81 -0
- data/lib/withruntime/generated/events.rb +60 -0
- data/lib/withruntime/generated/feedback.rb +96 -0
- data/lib/withruntime/generated/functions.rb +192 -0
- data/lib/withruntime/generated/identities.rb +68 -0
- data/lib/withruntime/generated/images.rb +391 -0
- data/lib/withruntime/generated/job_runs.rb +110 -0
- data/lib/withruntime/generated/jobs.rb +333 -0
- data/lib/withruntime/generated/keys.rb +261 -0
- data/lib/withruntime/generated/kit.rb +111 -0
- data/lib/withruntime/generated/me.rb +69 -0
- data/lib/withruntime/generated/networks.rb +72 -0
- data/lib/withruntime/generated/notebooks.rb +192 -0
- data/lib/withruntime/generated/otel.rb +94 -0
- data/lib/withruntime/generated/ports.rb +118 -0
- data/lib/withruntime/generated/previews.rb +124 -0
- data/lib/withruntime/generated/projects.rb +108 -0
- data/lib/withruntime/generated/roles.rb +68 -0
- data/lib/withruntime/generated/routes.rb +11 -0
- data/lib/withruntime/generated/runtime.rb +188 -0
- data/lib/withruntime/generated/sandboxes.rb +1835 -0
- data/lib/withruntime/generated/secrets.rb +294 -0
- data/lib/withruntime/generated/sessions.rb +143 -0
- data/lib/withruntime/generated/sites.rb +192 -0
- data/lib/withruntime/generated/snapshots.rb +32 -0
- data/lib/withruntime/generated/tunnels.rb +165 -0
- data/lib/withruntime/generated/usage.rb +287 -0
- data/lib/withruntime/generated/volumes.rb +61 -0
- data/lib/withruntime/generated/webhooks.rb +91 -0
- data/lib/withruntime/generated/workspaces.rb +192 -0
- data/lib/withruntime/signing.rb +162 -0
- data/lib/withruntime/version.rb +2 -2
- data/lib/withruntime.rb +5 -43
- metadata +45 -35
- data/lib/withruntime/agents.rb +0 -877
- data/lib/withruntime/api_defaults.rb +0 -17
- data/lib/withruntime/apps.rb +0 -377
- data/lib/withruntime/browsers.rb +0 -104
- data/lib/withruntime/builds.rb +0 -218
- data/lib/withruntime/ci.rb +0 -164
- data/lib/withruntime/client.rb +0 -140
- data/lib/withruntime/containers.rb +0 -39
- data/lib/withruntime/credentials.rb +0 -111
- data/lib/withruntime/fields.rb +0 -40
- data/lib/withruntime/file_watch.rb +0 -73
- data/lib/withruntime/images.rb +0 -258
- data/lib/withruntime/network_products.rb +0 -49
- data/lib/withruntime/parity_products.rb +0 -51
- data/lib/withruntime/products.rb +0 -560
- data/lib/withruntime/record.rb +0 -99
- data/lib/withruntime/reservations.rb +0 -76
- data/lib/withruntime/sandbox.rb +0 -770
- data/lib/withruntime/tar.rb +0 -292
- data/lib/withruntime/transport.rb +0 -575
- data/lib/withruntime/tunnel.rb +0 -275
- data/lib/withruntime/wallet.rb +0 -68
- data/lib/withruntime/websocket.rb +0 -384
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Generated by spec-gen from engines/front/crates/spec. Do not edit:
|
|
2
|
+
# change the spec and run `cargo run -p runtime-front-spec-gen -- write`.
|
|
3
|
+
|
|
4
|
+
require "uri"
|
|
5
|
+
require_relative "runtime"
|
|
6
|
+
require_relative "sandboxes"
|
|
7
|
+
|
|
8
|
+
module Withruntime
|
|
9
|
+
module Generated
|
|
10
|
+
# One run of a job: a machine made at one of its times, deleted when its command ended.
|
|
11
|
+
# - +id+: Its ID.
|
|
12
|
+
# - +object+: Always `job.run`.
|
|
13
|
+
# - +job+: Its job's ID.
|
|
14
|
+
# - +state+: Its machine's state: `starting` and `running` while it runs, `deleted` once it ended, `error` when it failed to start.
|
|
15
|
+
# - +at+: The time it is for: its schedule's, or when it was asked for.
|
|
16
|
+
# - +attempt+: Its attempt at that time, from 1.
|
|
17
|
+
# - +manual+: Someone asked for it (`run`), rather than its schedule.
|
|
18
|
+
# - +created_at+: When it was made.
|
|
19
|
+
# - +ended_at+: When its command ended.
|
|
20
|
+
# - +exit_code+: Its command's exit code, once it ended; none for one a signal or its timeout ended, or one deleted before its end.
|
|
21
|
+
# - +succeeded+: It ended with exit code 0.
|
|
22
|
+
# - +output_bytes+: How many bytes its command wrote, stdout and stderr together.
|
|
23
|
+
JobRun = Struct.new(:id, :object, :job, :state, :at, :attempt, :manual, :created_at, :ended_at, :exit_code, :succeeded, :output_bytes, keyword_init: true) do
|
|
24
|
+
def self.from(h)
|
|
25
|
+
return nil if h.nil?
|
|
26
|
+
|
|
27
|
+
new(
|
|
28
|
+
id: h["id"],
|
|
29
|
+
object: h["object"],
|
|
30
|
+
job: h["job"],
|
|
31
|
+
state: h["state"],
|
|
32
|
+
at: h["at"],
|
|
33
|
+
attempt: h["attempt"],
|
|
34
|
+
manual: h["manual"],
|
|
35
|
+
created_at: h["createdAt"],
|
|
36
|
+
ended_at: h["endedAt"],
|
|
37
|
+
exit_code: h["exitCode"],
|
|
38
|
+
succeeded: h["succeeded"],
|
|
39
|
+
output_bytes: h["outputBytes"],
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def to_wire
|
|
44
|
+
{
|
|
45
|
+
"id" => self.id,
|
|
46
|
+
"object" => self.object,
|
|
47
|
+
"job" => self.job,
|
|
48
|
+
"state" => self.state,
|
|
49
|
+
"at" => self.at,
|
|
50
|
+
"attempt" => self.attempt,
|
|
51
|
+
"manual" => self.manual,
|
|
52
|
+
"createdAt" => self.created_at,
|
|
53
|
+
"endedAt" => self.ended_at,
|
|
54
|
+
"exitCode" => self.exit_code,
|
|
55
|
+
"succeeded" => self.succeeded,
|
|
56
|
+
"outputBytes" => self.output_bytes,
|
|
57
|
+
}.compact
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# A run's output, stdout and stderr together in the order written, after a cursor: its last 256 KiB are kept.
|
|
62
|
+
# - +chunks+: The output, in the order it was written.
|
|
63
|
+
# - +next_cursor+: The cursor to read on from.
|
|
64
|
+
# - +truncated+: Output before what is kept was dropped, past the cursor.
|
|
65
|
+
# - +complete+: The run ended and nothing is left past the next cursor.
|
|
66
|
+
JobRunOutput = Struct.new(:chunks, :next_cursor, :truncated, :complete, keyword_init: true) do
|
|
67
|
+
def self.from(h)
|
|
68
|
+
return nil if h.nil?
|
|
69
|
+
|
|
70
|
+
new(
|
|
71
|
+
chunks: h["chunks"]&.map { |i| OutputChunk.from(i) },
|
|
72
|
+
next_cursor: h["nextCursor"],
|
|
73
|
+
truncated: h["truncated"],
|
|
74
|
+
complete: h["complete"],
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def to_wire
|
|
79
|
+
{
|
|
80
|
+
"chunks" => self.chunks&.map { |i| i&.to_wire },
|
|
81
|
+
"nextCursor" => self.next_cursor,
|
|
82
|
+
"truncated" => self.truncated,
|
|
83
|
+
"complete" => self.complete,
|
|
84
|
+
}.compact
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# One run of a job: a machine made at one of its times, deleted when its command ends. Its record (exit code, times, the last 256 KiB of its output) stays readable for 7 days after.
|
|
89
|
+
class JobRuns
|
|
90
|
+
def initialize(transport)
|
|
91
|
+
@transport = transport
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Lists a job's runs, oldest first unless `order` is `newest`, deleted ones included while their records are kept.
|
|
95
|
+
def list(job:, order: nil, cursor: nil, limit: nil)
|
|
96
|
+
Generated.page(@transport.request("GET", "/v2/job-runs", query: { "job" => job, "order" => order, "cursor" => cursor, "limit" => limit }, idempotent: true)) { |i| JobRun.from(i) }
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Returns a run.
|
|
100
|
+
def get(id)
|
|
101
|
+
JobRun.from(@transport.request("GET", "/v2/job-runs/#{URI.encode_www_form_component(id)}", idempotent: true))
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Returns a run's output after a cursor, stdout and stderr together in the order written, and the cursor to read on from. Its last 256 KiB are kept; truncated says when the cursor fell before them.
|
|
105
|
+
def output(id, cursor: nil, max_bytes: nil)
|
|
106
|
+
JobRunOutput.from(@transport.request("GET", "/v2/job-runs/#{URI.encode_www_form_component(id)}/output", query: { "cursor" => cursor, "maxBytes" => max_bytes }, idempotent: true))
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
# Generated by spec-gen from engines/front/crates/spec. Do not edit:
|
|
2
|
+
# change the spec and run `cargo run -p runtime-front-spec-gen -- write`.
|
|
3
|
+
|
|
4
|
+
require "uri"
|
|
5
|
+
require_relative "runtime"
|
|
6
|
+
require_relative "sandboxes"
|
|
7
|
+
|
|
8
|
+
module Withruntime
|
|
9
|
+
module Generated
|
|
10
|
+
# When a job runs: once, at `at`; or at each time of its `cron` in its `timezone`. One of the two.
|
|
11
|
+
# - +at+: The one time it runs.
|
|
12
|
+
# - +cron+: A cron expression of five fields (minute, hour, day of month, month, day of week), as cron reads them, or `@hourly`, `@daily`, `@weekly`, `@monthly` or `@yearly`.
|
|
13
|
+
# - +timezone+: The IANA timezone its cron's times are in (`America/Denver`), daylight saving included; UTC when omitted.
|
|
14
|
+
JobSchedule = Struct.new(:at, :cron, :timezone, keyword_init: true) do
|
|
15
|
+
def self.from(h)
|
|
16
|
+
return nil if h.nil?
|
|
17
|
+
|
|
18
|
+
new(
|
|
19
|
+
at: h["at"],
|
|
20
|
+
cron: h["cron"],
|
|
21
|
+
timezone: h["timezone"],
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def to_wire
|
|
26
|
+
{
|
|
27
|
+
"at" => self.at,
|
|
28
|
+
"cron" => self.cron,
|
|
29
|
+
"timezone" => self.timezone,
|
|
30
|
+
}.compact
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# How a failed run is run again: a run that ends with an exit code other than 0, or at its timeout.
|
|
35
|
+
# - +max_attempts+: Attempts in all for one time, the first included; 1 (no retry) when omitted. At least 1. At most 10. Default: 1.
|
|
36
|
+
# - +backoff_seconds+: Seconds from a failed attempt's end to the next. At least 0. At most 86400. Default: 30.
|
|
37
|
+
JobRetry = Struct.new(:max_attempts, :backoff_seconds, keyword_init: true) do
|
|
38
|
+
def self.from(h)
|
|
39
|
+
return nil if h.nil?
|
|
40
|
+
|
|
41
|
+
new(
|
|
42
|
+
max_attempts: h["maxAttempts"],
|
|
43
|
+
backoff_seconds: h["backoffSeconds"],
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def to_wire
|
|
48
|
+
{
|
|
49
|
+
"maxAttempts" => self.max_attempts,
|
|
50
|
+
"backoffSeconds" => self.backoff_seconds,
|
|
51
|
+
}.compact
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Which of its org's secrets each run gets, and under which variables.
|
|
56
|
+
# - +only+: The secrets each run gets in their own variables, by name: only those of them whose scope admits it; [] none. At most 64 items.
|
|
57
|
+
# - +env+: Variables each holding the value of one of the org's visible secrets whose scope admits the run, by the secret's name, `only` or not: `{"WEBSITE_TOKEN": "CRON_SECRET"}`.
|
|
58
|
+
JobSecrets = Struct.new(:only, :env, keyword_init: true) do
|
|
59
|
+
def self.from(h)
|
|
60
|
+
return nil if h.nil?
|
|
61
|
+
|
|
62
|
+
new(
|
|
63
|
+
only: h["only"],
|
|
64
|
+
env: h["env"],
|
|
65
|
+
)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def to_wire
|
|
69
|
+
{
|
|
70
|
+
"only" => self.only,
|
|
71
|
+
"env" => self.env,
|
|
72
|
+
}.compact
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# A job's settings: what each of its runs is made with.
|
|
77
|
+
# - +schedule+: When it runs.
|
|
78
|
+
# - +run+: The command each run runs; the run ends when it ends.
|
|
79
|
+
# - +retry+: How a failed run is run again; never when omitted.
|
|
80
|
+
# - +secrets+: Which of its org's secrets each run gets; every one whose scope admits it when omitted.
|
|
81
|
+
# - +vcpu+: Each run's vCPUs. At least 1. Default: 1.
|
|
82
|
+
# - +memory_gb+: Each run's memory in GB (1 GB is 1,024 MiB); a fraction is taken to the MiB (`0.5`). At least 1. Default: 1.
|
|
83
|
+
# - +disk_gb+: Each run's disk in GB, to the MiB, over a fresh copy of its image. At least 1. Default: 4.
|
|
84
|
+
# - +image+: The image each run boots, by name (its newest version), `name:version` or ID; Runtime's default image when omitted.
|
|
85
|
+
# - +user+: Who its command runs as: `runtime` (uid 1000, with passwordless sudo) or `root`. Its image's when omitted, else `runtime`.
|
|
86
|
+
# - +volumes+: Volumes each run attaches and mounts, at most one, in the job's project; a run waits while another machine holds it.
|
|
87
|
+
# - +max_cost+: The most one run may cost, in US dollars (`"0.50"`): a run pauses once it has cost that, as a machine at its maxCost does.
|
|
88
|
+
JobSettings = Struct.new(:schedule, :run, :retry, :secrets, :vcpu, :memory_gb, :disk_gb, :image, :user, :volumes, :max_cost, keyword_init: true) do
|
|
89
|
+
def self.from(h)
|
|
90
|
+
return nil if h.nil?
|
|
91
|
+
|
|
92
|
+
new(
|
|
93
|
+
schedule: JobSchedule.from(h["schedule"]),
|
|
94
|
+
run: SandboxRun.from(h["run"]),
|
|
95
|
+
retry: JobRetry.from(h["retry"]),
|
|
96
|
+
secrets: JobSecrets.from(h["secrets"]),
|
|
97
|
+
vcpu: h["vcpu"],
|
|
98
|
+
memory_gb: h["memoryGB"],
|
|
99
|
+
disk_gb: h["diskGB"],
|
|
100
|
+
image: h["image"],
|
|
101
|
+
user: h["user"],
|
|
102
|
+
volumes: h["volumes"]&.map { |i| VolumeMount.from(i) },
|
|
103
|
+
max_cost: h["maxCost"],
|
|
104
|
+
)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def to_wire
|
|
108
|
+
{
|
|
109
|
+
"schedule" => self.schedule&.to_wire,
|
|
110
|
+
"run" => self.run&.to_wire,
|
|
111
|
+
"retry" => self.retry&.to_wire,
|
|
112
|
+
"secrets" => self.secrets&.to_wire,
|
|
113
|
+
"vcpu" => self.vcpu,
|
|
114
|
+
"memoryGB" => self.memory_gb,
|
|
115
|
+
"diskGB" => self.disk_gb,
|
|
116
|
+
"image" => self.image,
|
|
117
|
+
"user" => self.user,
|
|
118
|
+
"volumes" => self.volumes&.map { |i| i&.to_wire },
|
|
119
|
+
"maxCost" => self.max_cost,
|
|
120
|
+
}.compact
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# A job to create: its schedule and run are required.
|
|
125
|
+
# - +schedule+: When it runs.
|
|
126
|
+
# - +run+: The command each run runs; the run ends when it ends.
|
|
127
|
+
# - +retry+: How a failed run is run again; never when omitted.
|
|
128
|
+
# - +secrets+: Which of its org's secrets each run gets; every one whose scope admits it when omitted.
|
|
129
|
+
# - +vcpu+: Each run's vCPUs. At least 1. Default: 1.
|
|
130
|
+
# - +memory_gb+: Each run's memory in GB (1 GB is 1,024 MiB); a fraction is taken to the MiB (`0.5`). At least 1. Default: 1.
|
|
131
|
+
# - +disk_gb+: Each run's disk in GB, to the MiB, over a fresh copy of its image. At least 1. Default: 4.
|
|
132
|
+
# - +image+: The image each run boots, by name (its newest version), `name:version` or ID; Runtime's default image when omitted.
|
|
133
|
+
# - +user+: Who its command runs as: `runtime` (uid 1000, with passwordless sudo) or `root`. Its image's when omitted, else `runtime`.
|
|
134
|
+
# - +volumes+: Volumes each run attaches and mounts, at most one, in the job's project; a run waits while another machine holds it.
|
|
135
|
+
# - +max_cost+: The most one run may cost, in US dollars (`"0.50"`): a run pauses once it has cost that, as a machine at its maxCost does.
|
|
136
|
+
# - +name+: Its name, unique in its project.
|
|
137
|
+
# - +labels+: Labels to find it by; each run carries them.
|
|
138
|
+
JobCreate = Struct.new(:schedule, :run, :retry, :secrets, :vcpu, :memory_gb, :disk_gb, :image, :user, :volumes, :max_cost, :name, :labels, keyword_init: true) do
|
|
139
|
+
def self.from(h)
|
|
140
|
+
return nil if h.nil?
|
|
141
|
+
|
|
142
|
+
new(
|
|
143
|
+
schedule: JobSchedule.from(h["schedule"]),
|
|
144
|
+
run: SandboxRun.from(h["run"]),
|
|
145
|
+
retry: JobRetry.from(h["retry"]),
|
|
146
|
+
secrets: JobSecrets.from(h["secrets"]),
|
|
147
|
+
vcpu: h["vcpu"],
|
|
148
|
+
memory_gb: h["memoryGB"],
|
|
149
|
+
disk_gb: h["diskGB"],
|
|
150
|
+
image: h["image"],
|
|
151
|
+
user: h["user"],
|
|
152
|
+
volumes: h["volumes"]&.map { |i| VolumeMount.from(i) },
|
|
153
|
+
max_cost: h["maxCost"],
|
|
154
|
+
name: h["name"],
|
|
155
|
+
labels: h["labels"],
|
|
156
|
+
)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def to_wire
|
|
160
|
+
{
|
|
161
|
+
"schedule" => self.schedule&.to_wire,
|
|
162
|
+
"run" => self.run&.to_wire,
|
|
163
|
+
"retry" => self.retry&.to_wire,
|
|
164
|
+
"secrets" => self.secrets&.to_wire,
|
|
165
|
+
"vcpu" => self.vcpu,
|
|
166
|
+
"memoryGB" => self.memory_gb,
|
|
167
|
+
"diskGB" => self.disk_gb,
|
|
168
|
+
"image" => self.image,
|
|
169
|
+
"user" => self.user,
|
|
170
|
+
"volumes" => self.volumes&.map { |i| i&.to_wire },
|
|
171
|
+
"maxCost" => self.max_cost,
|
|
172
|
+
"name" => self.name,
|
|
173
|
+
"labels" => self.labels,
|
|
174
|
+
}.compact
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# Why a time's run was not made and will not be tried again: the answer its create got. The job waits for its next time; a run made takes it off.
|
|
179
|
+
# - +at+: The time whose run was not made.
|
|
180
|
+
# - +status+: The HTTP status its create was answered with.
|
|
181
|
+
# - +code+: The error's code, as any call's error names it.
|
|
182
|
+
# - +message+: What went wrong.
|
|
183
|
+
# - +request_id+: The create's request ID, for support.
|
|
184
|
+
JobError = Struct.new(:at, :status, :code, :message, :request_id, keyword_init: true) do
|
|
185
|
+
def self.from(h)
|
|
186
|
+
return nil if h.nil?
|
|
187
|
+
|
|
188
|
+
new(
|
|
189
|
+
at: h["at"],
|
|
190
|
+
status: h["status"],
|
|
191
|
+
code: h["code"],
|
|
192
|
+
message: h["message"],
|
|
193
|
+
request_id: h["requestId"],
|
|
194
|
+
)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def to_wire
|
|
198
|
+
{
|
|
199
|
+
"at" => self.at,
|
|
200
|
+
"status" => self.status,
|
|
201
|
+
"code" => self.code,
|
|
202
|
+
"message" => self.message,
|
|
203
|
+
"requestId" => self.request_id,
|
|
204
|
+
}.compact
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
# A job.
|
|
209
|
+
# - +schedule+: When it runs.
|
|
210
|
+
# - +run+: The command each run runs; the run ends when it ends.
|
|
211
|
+
# - +retry+: How a failed run is run again; never when omitted.
|
|
212
|
+
# - +secrets+: Which of its org's secrets each run gets; every one whose scope admits it when omitted.
|
|
213
|
+
# - +vcpu+: Each run's vCPUs. At least 1. Default: 1.
|
|
214
|
+
# - +memory_gb+: Each run's memory in GB (1 GB is 1,024 MiB); a fraction is taken to the MiB (`0.5`). At least 1. Default: 1.
|
|
215
|
+
# - +disk_gb+: Each run's disk in GB, to the MiB, over a fresh copy of its image. At least 1. Default: 4.
|
|
216
|
+
# - +image+: The image each run boots, by name (its newest version), `name:version` or ID; Runtime's default image when omitted.
|
|
217
|
+
# - +user+: Who its command runs as: `runtime` (uid 1000, with passwordless sudo) or `root`. Its image's when omitted, else `runtime`.
|
|
218
|
+
# - +volumes+: Volumes each run attaches and mounts, at most one, in the job's project; a run waits while another machine holds it.
|
|
219
|
+
# - +max_cost+: The most one run may cost, in US dollars (`"0.50"`): a run pauses once it has cost that, as a machine at its maxCost does.
|
|
220
|
+
# - +id+: Its ID.
|
|
221
|
+
# - +object+: Always `job`.
|
|
222
|
+
# - +name+: Its name, unique in its project.
|
|
223
|
+
# - +state+: Where it is: `scheduled` (its runs are made at their times), `paused` (none is), `finished` (its one time ran).
|
|
224
|
+
# - +labels+: Its labels.
|
|
225
|
+
# - +next_run_at+: When its next run is made, or its next retry; none when paused or finished.
|
|
226
|
+
# - +last_error+: Why its last time's run was not made, when it was refused: that time failed and it waits for its next; none once a run is made.
|
|
227
|
+
# - +created_at+: When it was created.
|
|
228
|
+
# - +revision+: Its revision, changed by every change to it.
|
|
229
|
+
# - +deleted_at+: When it was deleted: a delete's answer, its state `deleted`.
|
|
230
|
+
Job = Struct.new(:schedule, :run, :retry, :secrets, :vcpu, :memory_gb, :disk_gb, :image, :user, :volumes, :max_cost, :id, :object, :name, :state, :labels, :next_run_at, :last_error, :created_at, :revision, :deleted_at, keyword_init: true) do
|
|
231
|
+
def self.from(h)
|
|
232
|
+
return nil if h.nil?
|
|
233
|
+
|
|
234
|
+
new(
|
|
235
|
+
schedule: JobSchedule.from(h["schedule"]),
|
|
236
|
+
run: SandboxRun.from(h["run"]),
|
|
237
|
+
retry: JobRetry.from(h["retry"]),
|
|
238
|
+
secrets: JobSecrets.from(h["secrets"]),
|
|
239
|
+
vcpu: h["vcpu"],
|
|
240
|
+
memory_gb: h["memoryGB"],
|
|
241
|
+
disk_gb: h["diskGB"],
|
|
242
|
+
image: h["image"],
|
|
243
|
+
user: h["user"],
|
|
244
|
+
volumes: h["volumes"]&.map { |i| VolumeMount.from(i) },
|
|
245
|
+
max_cost: h["maxCost"],
|
|
246
|
+
id: h["id"],
|
|
247
|
+
object: h["object"],
|
|
248
|
+
name: h["name"],
|
|
249
|
+
state: h["state"],
|
|
250
|
+
labels: h["labels"],
|
|
251
|
+
next_run_at: h["nextRunAt"],
|
|
252
|
+
last_error: JobError.from(h["lastError"]),
|
|
253
|
+
created_at: h["createdAt"],
|
|
254
|
+
revision: h["revision"],
|
|
255
|
+
deleted_at: h["deletedAt"],
|
|
256
|
+
)
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def to_wire
|
|
260
|
+
{
|
|
261
|
+
"schedule" => self.schedule&.to_wire,
|
|
262
|
+
"run" => self.run&.to_wire,
|
|
263
|
+
"retry" => self.retry&.to_wire,
|
|
264
|
+
"secrets" => self.secrets&.to_wire,
|
|
265
|
+
"vcpu" => self.vcpu,
|
|
266
|
+
"memoryGB" => self.memory_gb,
|
|
267
|
+
"diskGB" => self.disk_gb,
|
|
268
|
+
"image" => self.image,
|
|
269
|
+
"user" => self.user,
|
|
270
|
+
"volumes" => self.volumes&.map { |i| i&.to_wire },
|
|
271
|
+
"maxCost" => self.max_cost,
|
|
272
|
+
"id" => self.id,
|
|
273
|
+
"object" => self.object,
|
|
274
|
+
"name" => self.name,
|
|
275
|
+
"state" => self.state,
|
|
276
|
+
"labels" => self.labels,
|
|
277
|
+
"nextRunAt" => self.next_run_at,
|
|
278
|
+
"lastError" => self.last_error&.to_wire,
|
|
279
|
+
"createdAt" => self.created_at,
|
|
280
|
+
"revision" => self.revision,
|
|
281
|
+
"deletedAt" => self.deleted_at,
|
|
282
|
+
}.compact
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
# A command run in a fresh machine, once or on a cron schedule in a timezone. Each run is a machine made at its time, deleted when its command ends, and billed as any machine is; its exit code and its last 256 KiB of output are kept. Runs of one job never overlap: a time that comes while one runs is made once it ends, and times missed make one run.
|
|
287
|
+
class Jobs
|
|
288
|
+
def initialize(transport)
|
|
289
|
+
@transport = transport
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
# Creates a job. Its first run is made at its schedule's first time. Asked again with the same Idempotency-Key, it returns the same job.
|
|
293
|
+
def create(schedule: nil, run: nil, retry: nil, secrets: nil, vcpu: nil, memory_gb: nil, disk_gb: nil, image: nil, user: nil, volumes: nil, max_cost: nil, name: nil, labels: nil, idempotency_key: nil)
|
|
294
|
+
Job.from(@transport.request("POST", "/v2/jobs", body: { "schedule" => schedule, "run" => run, "retry" => binding.local_variable_get(:retry), "secrets" => secrets, "vcpu" => vcpu, "memoryGB" => memory_gb, "diskGB" => disk_gb, "image" => image, "user" => user, "volumes" => volumes, "maxCost" => max_cost, "name" => name, "labels" => labels }.compact, idempotency_key: idempotency_key, idempotent: true))
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
# Returns a job.
|
|
298
|
+
def get(id)
|
|
299
|
+
Job.from(@transport.request("GET", "/v2/jobs/#{URI.encode_www_form_component(id)}", idempotent: true))
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
# Lists the project's jobs, newest first.
|
|
303
|
+
def list(label: nil, cursor: nil, limit: nil)
|
|
304
|
+
Generated.page(@transport.request("GET", "/v2/jobs", query: { "label" => label, "cursor" => cursor, "limit" => limit }, idempotent: true)) { |i| Job.from(i) }
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
# Deletes a job: no run is made from then on, and a run in flight is ended. Its runs' records stay readable for 7 days.
|
|
308
|
+
def delete(id, idempotency_key: nil)
|
|
309
|
+
Job.from(@transport.request("DELETE", "/v2/jobs/#{URI.encode_www_form_component(id)}", idempotency_key: idempotency_key, idempotent: true))
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
# Pauses a job: no run is made at its times until it is resumed. A run in flight runs to its end.
|
|
313
|
+
def pause(id, idempotency_key: nil)
|
|
314
|
+
Job.from(@transport.request("POST", "/v2/jobs/#{URI.encode_www_form_component(id)}:pause", idempotency_key: idempotency_key, idempotent: true))
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
# Resumes a paused job: its next run is made at its schedule's next time from now.
|
|
318
|
+
def resume(id, idempotency_key: nil)
|
|
319
|
+
Job.from(@transport.request("POST", "/v2/jobs/#{URI.encode_www_form_component(id)}:resume", idempotency_key: idempotency_key, idempotent: true))
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# Changes a job's settings: each one named replaces its own, the rest are kept. Runs made from then on use them; one in flight runs as it was made. A new schedule's next run is at its next time from now.
|
|
323
|
+
def update(id, schedule: nil, run: nil, retry: nil, secrets: nil, vcpu: nil, memory_gb: nil, disk_gb: nil, image: nil, user: nil, volumes: nil, max_cost: nil, idempotency_key: nil)
|
|
324
|
+
Job.from(@transport.request("POST", "/v2/jobs/#{URI.encode_www_form_component(id)}:update", body: { "schedule" => schedule, "run" => run, "retry" => binding.local_variable_get(:retry), "secrets" => secrets, "vcpu" => vcpu, "memoryGB" => memory_gb, "diskGB" => disk_gb, "image" => image, "user" => user, "volumes" => volumes, "maxCost" => max_cost }.compact, idempotency_key: idempotency_key, idempotent: true))
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
# Makes a run now, beside its schedule; a paused job stays paused. Refused 409 while a run of it is in flight. Asked again with the same Idempotency-Key, it makes nothing more.
|
|
328
|
+
def run(id, idempotency_key: nil)
|
|
329
|
+
Job.from(@transport.request("POST", "/v2/jobs/#{URI.encode_www_form_component(id)}:run", idempotency_key: idempotency_key, idempotent: true))
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
end
|