Class: BagMoveJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/bag_move_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(queue_item, errors: [], validator: ChipmunkBagValidator.new(queue_item.package, errors)) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/jobs/bag_move_job.rb', line 8

def perform(queue_item, errors: [], validator: ChipmunkBagValidator.new(queue_item.package, errors))
  @queue_item = queue_item
  @src_path = queue_item.package.src_path
  @dest_path = queue_item.package.dest_path
  @errors = errors

  begin
    # TODO
    #  - if all validation succeeds:
    #    - start a transaction that updates the request to complete
    #    - move the bag into place
    #    - success: commit the transaction
    #    - failure (exception) - transaction automatically rolls back

    validate_with(validator)
  rescue StandardError => exception
    errors << "#{exception.backtrace.first}: #{exception.message} (#{exception.class})"
    errors << exception.backtrace.drop(1).map {|s| "\t#{s}" }
    record_failure(errors)
    raise exception
  end
end