Module: EnqueueExport

Defined in:
lib/enqueue_export.rb,
lib/enqueue_export/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.1.3"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#pending_exportsObject

Returns the value of attribute pending_exports.



7
8
9
# File 'lib/enqueue_export.rb', line 7

def pending_exports
  @pending_exports
end

Class Method Details

.batch_size(data) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/enqueue_export.rb', line 52

def self.batch_size(data)
  args = {
    channel_id: data[0][2],
    name: 'batch_size'
  }
  size = Config.find_by(args).value.to_i
  data[1].in_groups_of(size, false)
end

.delayed_job(model, worker_id) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/enqueue_export.rb', line 61

def self.delayed_job(model, worker_id)
  service = if %w[export response].include? model
              Kernel.const_get("Worker::#{model.capitalize}Service")
            else
              Kernel.const_get("Check#{model.capitalize}Service")
            end
  Delayed::Job.enqueue(service.new(worker_id: worker_id))
end

.exportObject



24
25
26
27
# File 'lib/enqueue_export.rb', line 24

def self.export
  @pending_export = PendingExport.where(local_feed_id: nil, worker_id: nil)
  @pending_export.where(response_id: nil, processed: false)
end

.generate_idObject



20
21
22
# File 'lib/enqueue_export.rb', line 20

def self.generate_id
  SecureRandom.hex(32)
end

.group_by(model) ⇒ Object



46
47
48
49
50
# File 'lib/enqueue_export.rb', line 46

def self.group_by(model)
  public_send(model).group_by do |obj|
    [obj.mode, obj., obj.channel_id]
  end.to_a
end

.perform(model) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/enqueue_export.rb', line 9

def self.perform(model)
  group_by(model).each do |data|
    batch_size(data).each do |batch|
      worker_id = generate_id
      ids = batch.map(&:id)
      public_send(model).where(id: ids).update_all(worker_id: worker_id)
      delayed_job(model, worker_id)
    end
  end
end

.qcObject



42
43
44
# File 'lib/enqueue_export.rb', line 42

def self.qc
  @pending_qc = PendingQc.where(worker_id: nil)
end

.responseObject



29
30
31
32
# File 'lib/enqueue_export.rb', line 29

def self.response
  @pending_export = PendingExport.where(local_feed_id: nil, worker_id: nil)
  @pending_export.where(processed: false).where.not(response_id: nil)
end

.validityObject



34
35
36
37
38
39
40
# File 'lib/enqueue_export.rb', line 34

def self.validity
  @pending_validity = PendingValidity.where(
    worker_id: nil,
    validity: false,
    processed: false
  )
end