Class: BarnyardHarvester::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/barnyard_harvester/queue.rb,
lib/barnyard_harvester/hash_queue.rb

Direct Known Subclasses

AddQueue, ChangeQueue, DeleteQueue

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Queue

Returns a new instance of Queue.



49
50
51
52
53
54
55
56
57
# File 'lib/barnyard_harvester/queue.rb', line 49

def initialize(args)

  @debug = args.fetch(:debug) { false }
  @log = args.fetch(:logger) { Logger.new(STDOUT) }
  @crop_number = args.fetch(:crop_number) { raise "You must provide :crop_number" }

  @q = BarnyardHarvester::GenericQueue.new(args)

end

Instance Method Details

#enqueue(queue, harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value, old_value) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/barnyard_harvester/queue.rb', line 13

def enqueue(queue, harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value, old_value)

  payload = Hash.new
  payload[:queued_at] = Time.now
  payload[:harvester_uuid] = harvester_uuid
  payload[:change_uuid] = change_uuid
  payload[:crop_number] = crop_number
  payload[:primary_key] = primary_key
  payload[:transaction_type] = transaction_type
  payload[:value] = value
  payload[:old_value] = old_value

  json_payload = payload.to_json

  @q.push(queue,json_payload)
  @q.push(QUEUE_CHANGE,json_payload)

end

#flushObject

Flush any data if needed.



74
75
# File 'lib/barnyard_harvester/queue.rb', line 74

def flush
end

#log_run(harvester_uuid, crop_number, began_at, ended_at, source_count, change_count, add_count, delete_count) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/barnyard_harvester/queue.rb', line 32

def log_run(harvester_uuid, crop_number, began_at, ended_at, source_count, change_count, add_count, delete_count)

  payload = Hash.new
  payload[:time] = Time.now
  payload[:harvester_uuid] = harvester_uuid
  payload[:crop_number] = crop_number
  payload[:began_at] = began_at
  payload[:ended_at] = ended_at
  payload[:source_count] = source_count
  payload[:change_count] = change_count
  payload[:add_count] = add_count
  payload[:delete_count] = delete_count

  @q.push(QUEUE_HARVESTER,payload.to_json)

end

#push(harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value, old_value = Hash.new) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/barnyard_harvester/queue.rb', line 59

def push(harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value, old_value=Hash.new)
  check_key primary_key

  enqueue(QUEUE_FARMER, harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value.to_json, old_value.to_json)

  message = "RabbitQueue: #{QUEUE_FARMER}, Now: #{DateTime.now}, Harvester:#{harvester_uuid}, Change:#{change_uuid} crop_number: #{crop_number}, key: #{primary_key}, transaction_type: #{transaction_type})"

  if @log.level == Logger::DEBUG
    message += ", value: #{value.to_json}, old_value: #{old_value.to_json}"
    @log.debug message
  end
end