hirefire-resource 0.1.3 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f76249632b57bc4180ff62be419e4d327fac2f9c
4
- data.tar.gz: 8994e97e741c960facf72acb6d0185d20a810c02
3
+ metadata.gz: 0e0b10eb9ebd32206b2a2b8f3fa6c9a8b5dda5f2
4
+ data.tar.gz: 1c4395b5cdc157db1c229dfcb3d154fd931c7e3f
5
5
  SHA512:
6
- metadata.gz: 12e1072617b7af769452d73a6db73d55eceab0e27144ca454a982e7758fcceb9e87a414b0a48e3905533e7d4dba329e64d1faed9c06ab6e1d71e8cdabeb89e11
7
- data.tar.gz: 95f776786bd20be9ac4959d09cb048ffdcb7be81d19b3a9f0f41d70c195c51724649854e0dfacf24d0d963b0b151dd3e9e8df1ed1d5b5676d3fdc932cadf7302
6
+ metadata.gz: 633c624c86b25ba906651366a95b1ea202ea1e403f8b26737ee09ccd463a6c02d73127c75fdc3eacf8217c8ab1ed70754d80e66a8cb3656f3fb1eaf33993c0e8
7
+ data.tar.gz: 507b88dee198030dd3cd5063da0804b56b8f14a9e3384df30af8edefeeb321b7a2fe17e4fa56d5af39996dbd52dc590582bb879e1e0dad9af350ef89d878b0af
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "hirefire-resource"
5
- gem.version = "0.1.3"
5
+ gem.version = "0.2.0"
6
6
  gem.platform = Gem::Platform::RUBY
7
7
  gem.authors = "Michael van Rooijen"
8
8
  gem.email = "michael@hirefire.io"
@@ -6,35 +6,48 @@ module HireFire
6
6
  module Job
7
7
  extend self
8
8
 
9
- # Determines whether `ActiveRecord (3)` or `Mongoid` is being used.
10
- # Once determined, it will build the appropriate query criteria in order
11
- # to count the amount of jobs in a given queue and return the result.
9
+ # Returns the job quantity for the provided queue(s).
12
10
  #
13
11
  # @example Delayed::Job Macro Usage
14
- # HireFire::Macro::Delayed::Job.queue # all queues
15
- # HireFire::Macro::Delayed::Job.queue("email") # only email queue
16
- # HireFire::Macro::Delayed::Job.queue("audio", "video") # audio and video queues
17
12
  #
18
- # @param [Array] queues provide one or more queue names, or none for "all".
13
+ # # all queues using ActiveRecord mapper.
14
+ # HireFire::Macro::Delayed::Job.queue(:mapper => :active_record)
15
+ #
16
+ # # only "email" queue with Mongoid mapper.
17
+ # HireFire::Macro::Delayed::Job.queue("email", :mapper => :mongoid)
19
18
  #
19
+ # # "audio" and "video" queues with ActiveRecord mapper.
20
+ # HireFire::Macro::Delayed::Job.queue("audio", "video", :mapper => :active_record)
21
+ #
22
+ # @param [Array] queues provide one or more queue names, or none for "all".
23
+ # Last argument can pass in a Hash containing :mapper => :active_record or :mapper => :mongoid
20
24
  # @return [Integer] the number of jobs in the queue(s).
25
+ #
21
26
  def queue(*queues)
22
27
  queues.flatten!
23
28
 
24
- if defined?(Mongoid)
29
+ if queues.last.is_a?(Hash)
30
+ options = queues.pop
31
+ else
32
+ options = {}
33
+ end
34
+
35
+ case options[:mapper]
36
+ when :active_record
25
37
  c = ::Delayed::Job
26
38
  c = c.where(:failed_at => nil)
27
- c = c.where(:run_at.lte => Time.now.utc)
28
- c = c.where(:queue.in => queues) unless queues.empty?
39
+ c = c.where("run_at <= ?", Time.now.utc)
40
+ c = c.where(:queue => queues) unless queues.empty?
29
41
  c.count
30
- elsif defined?(ActiveRecord)
42
+ when :mongoid
31
43
  c = ::Delayed::Job
32
44
  c = c.where(:failed_at => nil)
33
- c = c.where("run_at <= ?", Time.now.utc)
34
- c = c.where(:queue => queues) unless queues.empty?
45
+ c = c.where(:run_at.lte => Time.now.utc)
46
+ c = c.where(:queue.in => queues) unless queues.empty?
35
47
  c.count
36
48
  else
37
- raise "HireFire could not detect ActiveRecord or Mongoid for HireFire::Macro::Delayed::Job."
49
+ raise %{Must pass in :mapper => :active_record or :mapper => :mongoid\n} +
50
+ %{For example: HireFire::Macro::Delayed::Job.queue("worker", :mapper => :active_record)}
38
51
  end
39
52
  end
40
53
  end
@@ -13,10 +13,10 @@ module HireFire
13
13
  # HireFire::Macro::QC.queue("email") # counts the `email` queue.
14
14
  #
15
15
  # @param [String, Symbol, nil] queue the queue name to count. (default: `default`)
16
- #
17
16
  # @return [Integer] the number of jobs in the queue(s).
17
+ #
18
18
  def queue(queue = "default")
19
- ::QC::Queries.count(queue.to_s)
19
+ ::QC::Worker.new(:q_name => queue.to_s).queue.count
20
20
  end
21
21
  end
22
22
  end
@@ -13,8 +13,8 @@ module HireFire
13
13
  # HireFire::Macro::Qu.queue("audio", "video") # audio and video queues
14
14
  #
15
15
  # @param [Array] queues provide one or more queue names, or none for "all".
16
- #
17
16
  # @return [Integer] the number of jobs in the queue(s).
17
+ #
18
18
  def queue(*queues)
19
19
  queues = ::Qu.backend.queues if queues.empty?
20
20
  queues.flatten.inject(0) { |memo, queue| memo += ::Qu.backend.length(queue); memo }
@@ -13,8 +13,8 @@ module HireFire
13
13
  # HireFire::Macro::Resque.queue("audio", "video") # audio and video queues
14
14
  #
15
15
  # @param [Array] queues provide one or more queue names, or none for "all".
16
- #
17
16
  # @return [Integer] the number of jobs in the queue(s).
17
+ #
18
18
  def queue(*queues)
19
19
  queues = queues.flatten.map(&:to_s)
20
20
  queues = ::Resque.queues if queues.empty?
@@ -13,8 +13,8 @@ module HireFire
13
13
  # HireFire::Macro::Sidekiq.queue("audio", "video") # audio and video queues
14
14
  #
15
15
  # @param [Array] queues provide one or more queue names, or none for "all".
16
- #
17
16
  # @return [Integer] the number of jobs in the queue(s).
17
+ #
18
18
  def queue(*queues)
19
19
  queues = queues.flatten.map(&:to_s)
20
20
  queues = ::Sidekiq::Stats.new.queues.map { |name, _| name } if queues.empty?
@@ -7,6 +7,7 @@ module HireFire
7
7
  # and `ENV["HIREFIRE_TOKEN"]` in `@token` for convenience.
8
8
  #
9
9
  # @param [ActionDispatch::Routing::RouteSet] app.
10
+ #
10
11
  def initialize(app)
11
12
  @app = app
12
13
  @token = ENV["HIREFIRE_TOKEN"]
@@ -16,6 +17,7 @@ module HireFire
16
17
  # Otherwise, fall through to the rest of the middleware below HireFire::Middleware.
17
18
  #
18
19
  # @param [Hash] env containing request information.
20
+ #
19
21
  def call(env)
20
22
  @env = env
21
23
 
@@ -35,6 +37,7 @@ module HireFire
35
37
  # This url will be requested every minute by HireFire in order to fetch dyno data.
36
38
  #
37
39
  # @return [text/html, application/json] based on whether the `test` or `info` url was requested.
40
+ #
38
41
  def each(&block)
39
42
  if test?
40
43
  block.call "HireFire Middleware Found!"
@@ -48,6 +51,7 @@ module HireFire
48
51
  # Generates a JSON string based on the dyno data.
49
52
  #
50
53
  # @return [String] in JSON format.
54
+ #
51
55
  def dynos
52
56
  dyno_data = HireFire::Resource.dynos.inject(String.new) do |json, dyno|
53
57
  json << %|,{"name":"#{dyno[:name]}","quantity":#{dyno[:quantity].call || "null"}}|; json
@@ -59,6 +63,7 @@ module HireFire
59
63
  # Returns true if the PATH_INFO matches the test url.
60
64
  #
61
65
  # @return [Boolean] true if the requested url matches the test url.
66
+ #
62
67
  def test?
63
68
  @env["PATH_INFO"] == "/hirefire/test"
64
69
  end
@@ -66,6 +71,7 @@ module HireFire
66
71
  # Returns true if the PATH_INFO matches the info url.
67
72
  #
68
73
  # @return [Boolean] true if the requested url matches the info url.
74
+ #
69
75
  def info?
70
76
  @env["PATH_INFO"] == "/hirefire/#{@token || "development"}/info"
71
77
  end
@@ -5,6 +5,7 @@ module HireFire
5
5
  extend self
6
6
 
7
7
  # @return [Array] The configured dynos.
8
+ #
8
9
  attr_accessor :dynos
9
10
 
10
11
  # Sets the `@dynos` instance variable to an empty Array to hold all the dyno configuration.
@@ -17,6 +18,7 @@ module HireFire
17
18
  # end
18
19
  #
19
20
  # @yield [HireFire::Resource] to allow for block-style configuration.
21
+ #
20
22
  def configure
21
23
  @dynos ||= []
22
24
  yield self
@@ -26,6 +28,7 @@ module HireFire
26
28
  #
27
29
  # @param [Symbol, String] name the name of the dyno as defined in the Procfile.
28
30
  # @param [Proc] block an Integer containing the quantity calculation logic.
31
+ #
29
32
  def dyno(name, &block)
30
33
  @dynos << { :name => name, :quantity => block }
31
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hirefire-resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael van Rooijen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-12 00:00:00.000000000 Z
11
+ date: 2013-09-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: HireFire - The Heroku Dyno Manager
14
14
  email: michael@hirefire.io