From 0bd5ce9cc189f136353cdf559c88e953850b58e4 Mon Sep 17 00:00:00 2001 From: Tony Fabeen Oreste Date: Tue, 21 Apr 2020 18:26:15 +0200 Subject: [PATCH 1/2] Adds support to stop jobs --- lib/nomad/api/job.rb | 28 ++++++++++++++++++++++++++++ spec/integration/api/job_spec.rb | 10 ++++++++++ 2 files changed, 38 insertions(+) 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/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") From e82e70eb7dd8b71020b9b037e46c83160f74e871 Mon Sep 17 00:00:00 2001 From: Tony Fabeen Oreste Date: Tue, 21 Apr 2020 19:23:54 +0200 Subject: [PATCH 2/2] bump up version --- lib/nomad/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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