sidekiq

Ruby code posted
created at 24 Aug 17:23

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class StatusNotifier
  include Sidekiq::Worker
  include Sidetiq::Schedulable

  recurrence { minutely }
  sidekiq_options retry: false

  def perform options={}
    Grow.not_updated.each do |grow|
      begin
        current_status = HTTParty.get(grow.api_location + "/current.json")
        if current_status.code < 400
          unless (current_status["humidity"].between?(grow.hum_low, grow.hum_high) and current_status["temperature"].between?(grow.temp_low, grow.temp_high))
            status=Status.new current_status
            unless Status.exists?(status.id)
              if status.save!
                Notification.new(grow: grow, status: status, dismissed: false, content: "params_not_in_range").save!
              end
            end
          end
        end
      rescue
        logger.warn("Job error: Error fetching current status: Grow##{grow.id} (#{grow.api_location})");
      end
    end
  end

end
950 Bytes in 3 ms with coderay