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

payrollhero / dispatch-rider / #3013

17 Aug 2022 11:01PM UTC coverage: 49.061% (-36.1%) from 85.141%
#3013

push

web-flow
setup coveralls (#81)

575 of 1172 relevant lines covered (49.06%)

0.49 hits per line

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

39.39
/lib/dispatch-rider/queue_services/file_system/queue.rb
1
# This is a queue implementation for the queue service based on file systems
2
module DispatchRider
1✔
3
  module QueueServices
1✔
4
    class FileSystem < Base
1✔
5
      class Queue
1✔
6
        def initialize(path)
1✔
7
          FileUtils.mkdir_p(path)
×
8
          @path = path
×
9
        end
10

11
        def add(item)
1✔
12
          name_base = "#{@path}/#{Time.now.to_f}"
×
13
          File.open("#{name_base}.inprogress", "w"){ |f| f.write(item) }
×
14
          FileUtils.mv("#{name_base}.inprogress", "#{name_base}.ready")
×
15
        end
16

17
        def pop
1✔
18
          file_path = next_item(10)
×
19
          return nil unless file_path
×
20
          file_path_inflight = file_path.gsub(/\.ready$/, '.inflight')
×
21
          FileUtils.mv(file_path, file_path_inflight)
×
22
          File.new(file_path_inflight)
×
23
        end
24

25
        def put_back(item)
1✔
26
          add(item)
×
27
          remove(item)
×
28
        end
29

30
        def remove(item)
1✔
31
          item.close
×
32
          File.unlink(item.path)
×
33
        end
34

35
        def size
1✔
36
          file_paths.size
×
37
        end
38

39
        private
1✔
40

41
        # Long polling next item fetcher
42
        # allows to sleep between checks for a new file and not run the main loop as much
43
        def next_item(timeout = 10.seconds)
1✔
44
          Timeout.timeout(timeout) do
×
45
            sleep 1 until file_paths.first
×
46
            file_paths.first
×
47
          end
48
        rescue Timeout::Error
49
          nil
×
50
        end
51

52
        def file_paths
1✔
53
          Dir["#{@path}/*.ready"]
×
54
        end
55
      end
56
    end
57
  end
58
end
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

© 2026 Coveralls, Inc