Class: QueueItemBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/queue_item_builder.rb

Instance Method Summary collapse

Constructor Details

#initializeQueueItemBuilder


5
# File 'lib/queue_item_builder.rb', line 5

def initialize; end

Instance Method Details

#create(request) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/queue_item_builder.rb', line 7

def create(request)
  duplicate = QueueItem.where(package: request, status: [:pending, :done]).first
  unless duplicate.nil?
    return :duplicate, duplicate
  end

  queue_item = QueueItem.new(package: request)
  if queue_item.valid?
    queue_item.save!
    BagMoveJob.perform_later(queue_item)
    return :created, queue_item
  else
    return :invalid, queue_item
  end
end