Class: CartonLabelWorker
Instance Attribute Summary
#broadcast_status_updates
Instance Method Summary
collapse
#at, #store, #total
Instance Method Details
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'app/workers/carton_label_worker.rb', line 8
def perform(options={})
options = options.with_indifferent_access
shipment_ids = options['shipment_ids'].presence || []
shipments = Shipment.where(id: shipment_ids)
return_existing = options[:return_existing].to_b
print_profile_id = options['print_profile_id']
print_profile_id = nil if print_profile_id == 'pdf'
if print_profile_id
print_profile = PrintProfile.find(print_profile_id)
else
pdfs = [] end
total_shipments = shipments.size
total total_shipments
num_labels = 0
shipments.each do |shipment|
num_labels += 1
upload = shipment.generate_and_attach_sscc_label(return_existing: return_existing)
at(num_labels, "At #{num_labels} of #{total_shipments}, shipment #{shipment.reference_number}")
if print_profile
print_profile.print_upload(upload)
else
pdfs << upload
end
end
results = {}
results[:redirect_to] = options['redirect_to']
if pdfs.present?
file_name = "combined_carton_label_#{Time.current.to_fs(:no_spaces)}.pdf"
temp_location = Upload.temp_location(file_name)
if pdfs.size > 1
pdf = PdfTools.combine(pdfs, output_file_path: temp_location)
upload = Upload.uploadify(pdf, 'carton_label', nil, file_name, false, 24.hours.from_now)
else upload = pdfs.first
end
results[:upload_id] = upload.id
end
store upload_id: results[:upload_id]
store redirect_to: results[:redirect_to]
end
|