diff --git a/lib/nomad/api/job.rb b/lib/nomad/api/job.rb index 89b9ee1..2b0ebb1 100644 --- a/lib/nomad/api/job.rb +++ b/lib/nomad/api/job.rb @@ -49,6 +49,16 @@ def read(name, **options) json = client.get("/v1/job/#{CGI.escape(name)}", options) return JobVersion.decode(json) end + + # Stops the job with the given name. + # + # @param [String] name The job name (ID). + # + # @return [JobStop] + def stop(name, **options) + json = client.delete("/v1/job/#{CGI.escape(name)}", options) + return JobStop.decode(json) + end end class JobItem < Response @@ -1030,4 +1040,22 @@ class JobDispatchPayload < Response # @return [String] field :File, as: :file, load: :string_as_nil end + + class JobStop < Response + # @!attribute [r] eval_id + # The job eval_id. + # @return [String] + field :EvalID, as: :eval_id, load: :string_as_nil + + # @!attribute [r] eval_create_index + # The job eval_create_index. + # @return [Integer] + field :EvalCreateIndex, as: :eval_create_index + + # @!attribute [r] job_modify_index + # The job job_modify_index. + # @return [Integer] + field :JobModifyIndex, as: :job_modify_index + + end end diff --git a/lib/nomad/version.rb b/lib/nomad/version.rb index d7bcd87..01995e9 100644 --- a/lib/nomad/version.rb +++ b/lib/nomad/version.rb @@ -1,3 +1,3 @@ module Nomad - VERSION = "0.1.0" + VERSION = "0.2.0" end diff --git a/spec/integration/api/job_spec.rb b/spec/integration/api/job_spec.rb index 6bd3343..63a29aa 100644 --- a/spec/integration/api/job_spec.rb +++ b/spec/integration/api/job_spec.rb @@ -28,6 +28,16 @@ module Nomad end end + describe "#stop" do + it "stops a job" do + job = JSON.parse(File.read(File.expand_path("../../../support/jobs/job.json", __FILE__))) + subject.create(job) + result = subject.stop("job") + + expect(result).to be_a(JobStop) + end + end + describe "#read" do it "reads a job" do job = subject.read("job")