• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

payrollhero / dispatch-rider / #3015

02 Sep 2022 11:22PM UTC coverage: 0.409% (-84.7%) from 85.154%
#3015

push

web-flow
Layout/SpaceInsideStringInterpolation-20220901233630 (#89)

* :police_car: regenerate rubocop todo

* :police_car: Layout/SpaceInsideStringInterpolation

* :police_car: regenerate rubocop todo

Co-authored-by: Rubocop Challenger <rubocop@payrollhero.com>

0 of 1 new or added line in 1 file covered. (0.0%)

1529 existing lines in 63 files now uncovered.

7 of 1711 relevant lines covered (0.41%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/dispatch-rider/scheduled_job.rb
UNCOV
1
require "active_record"
×
2

3
# @note: Later this could be pulled out to its own gem and included depending on what ORM the user
4
# prefers. Something like:
5
# @example
6
#  gem "dispatch_rider-active_record"
7
#  gem "dispatch_rider-rom" # Ruby Object Mapper
8
#  gem "dispatch_rider-mongo_mapper"
9
#  gem "dispatch_rider-ohm"
UNCOV
10
module DispatchRider
×
UNCOV
11
  class ScheduledJob < ActiveRecord::Base
×
UNCOV
12
    class << self
×
UNCOV
13
      def publisher
×
UNCOV
14
        @publisher ||= Publisher.new
×
UNCOV
15
      end
×
16

17
      # @param [ActiveSupport::Duration] every
18
      # @example: DispatchRider::ScheduledJob.publish_due_jobs every 1.minute
UNCOV
19
      def publish_due_jobs(every: nil)
×
UNCOV
20
        loop {
×
UNCOV
21
          claim_stub = get_new_claim_stub
×
UNCOV
22
          due.unclaimed.update_all claim_stub
×
UNCOV
23
          due.claimed_by(claim_stub[:claim_id]).find_each(&:publish)
×
UNCOV
24
          every ? sleep(every) : break # until the next loop
×
UNCOV
25
        }
×
UNCOV
26
      end
×
27

UNCOV
28
      private
×
29

UNCOV
30
      def get_new_claim_stub
×
UNCOV
31
        { claim_id: SecureRandom.uuid, claim_expires_at: 30.minutes.from_now }
×
UNCOV
32
      end
×
UNCOV
33
    end
×
34

UNCOV
35
    serialize :destinations
×
UNCOV
36
    serialize :message
×
37

UNCOV
38
    validates :scheduled_at,
×
UNCOV
39
              :destinations,
×
UNCOV
40
              :message,
×
UNCOV
41
              presence: true
×
42

UNCOV
43
    scope :due, -> (time = Time.now) { where "scheduled_at <= ?", time }
×
UNCOV
44
    scope :claimed_by, -> (claim_id) { where(claim_id: claim_id).where "claim_expires_at > ?", Time.now }
×
UNCOV
45
    scope :unclaimed, -> { where "claim_expires_at IS NULL OR claim_expires_at <= ?", Time.now }
×
46

UNCOV
47
    def publish
×
UNCOV
48
      publisher.publish(destinations: destinations, message: message)
×
49

UNCOV
50
      destroy # once published
×
UNCOV
51
    end
×
52

UNCOV
53
    private
×
54

UNCOV
55
    delegate :publisher, to: :"self.class"
×
UNCOV
56
  end
×
UNCOV
57
end
×
58

UNCOV
59
require_relative "scheduled_job/migration"
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc