-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implements a mosquito api for reading queues and fetching job runs fr…
…om them
- Loading branch information
Showing
5 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require "../../spec_helper" | ||
|
||
describe Mosquito::Api::JobRun do | ||
let(job_classes) { | ||
[QueuedTestJob, PassingJob, FailingJob, QueueHookedTestJob] | ||
} | ||
let(queued_test_job) { QueuedTestJob.new } | ||
let(passing_job) { PassingJob.new } | ||
|
||
it "can fetch a list of current queues" do | ||
clean_slate do | ||
queued_test_job.enqueue | ||
passing_job.enqueue | ||
expected_queues = ["queued_test_job", "passing_job"].sort | ||
queues = Mosquito::Api::Queue.all | ||
assert_equal 2, queues.size | ||
assert_equal expected_queues, queues.map(&.name).sort | ||
end | ||
end | ||
|
||
it "can fetch the size of a queue" do | ||
clean_slate do | ||
job_classes.map(&.new).each(&.enqueue) | ||
queues = Mosquito::Api::Queue.all | ||
queues.each do |queue| | ||
assert_equal 1, queue.size | ||
end | ||
end | ||
end | ||
|
||
it "can fetch the size details of a queue" do | ||
clean_slate do | ||
job_classes.map(&.new).each(&.enqueue) | ||
queues = Mosquito::Api::Queue.all | ||
sizes = queues.map(&.size_details) | ||
sizes.each do |size| | ||
assert_equal 1, size["waiting"] | ||
assert_equal 0, size["scheduled"] | ||
assert_equal 0, size["pending"] | ||
assert_equal 0, size["dead"] | ||
end | ||
end | ||
end | ||
|
||
it "can fetch job runs from a queue" do | ||
clean_slate do | ||
job_classes.each do |job_class| | ||
job = job_class.new | ||
job.enqueue | ||
api = Mosquito::Api::Queue.new job_class.queue.name | ||
job_runs = api.waiting_job_runs | ||
assert_equal 1, job_runs.size | ||
assert_equal job.class.name.underscore, job_runs.first.type | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Mosquito::Api | ||
class Queue | ||
getter name : String | ||
|
||
private property backend : Mosquito::Backend | ||
|
||
def self.all : Array(Queue) | ||
Mosquito.backend.list_queues.map { |name| new name } | ||
end | ||
|
||
def initialize(@name) | ||
@backend = Mosquito.backend.named name | ||
end | ||
|
||
{% for name in Mosquito::Backend::QUEUES %} | ||
def {{name.id}}_job_runs : Array(JobRun) | ||
backend.dump_{{name.id}}_q | ||
.map { |task_id| JobRun.new task_id } | ||
end | ||
{% end %} | ||
|
||
def size : Int64 | ||
backend.size(include_dead: false) | ||
end | ||
|
||
def size_details : Hash(String, Int64) | ||
sizes = {} of String => Int64 | ||
{% for name in Mosquito::Backend::QUEUES %} | ||
sizes["{{name.id}}"] = backend.{{name.id}}_size | ||
{% end %} | ||
sizes | ||
end | ||
|
||
def <=>(other) | ||
name <=> other.name | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters