Class: Diffity::Uploaders::Concurrent

Inherits:
Object
  • Object
show all
Defined in:
lib/diffity/uploaders/concurrent.rb

Constant Summary collapse

MAX_NO_OF_THREADS =
20

Instance Method Summary collapse

Constructor Details

#initialize(run_id) ⇒ Concurrent

Returns a new instance of Concurrent.



8
9
10
11
12
# File 'lib/diffity/uploaders/concurrent.rb', line 8

def initialize(run_id)
  @run_id = run_id
  @pool = ::Concurrent::FixedThreadPool.new(MAX_NO_OF_THREADS)
  @screenshots_taken = 0
end

Instance Method Details

#enqueue(identifier, browser, device, os, browser_version, device_name, os_version) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/diffity/uploaders/concurrent.rb', line 14

def enqueue(identifier, browser, device, os, browser_version,
            device_name, os_version)
  @screenshots_taken += 1

  @pool.post do
    Diffity::Utils
      .upload_image(@run_id, identifier, browser, device, os,
                    browser_version, device_name, os_version)
  end
end

#wrapupObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/diffity/uploaders/concurrent.rb', line 25

def wrapup
  retries = 180           # 30 mins

  # if all screenshots are not uploaded, wait.
  until @screenshots_taken == @pool.completed_task_count
    retries -= 1
    break if retries.zero?

    sleep 10
  end

  @pool.shutdown
  @pool.wait_for_termination
end