app/models/extface/device.rb in extface-0.4.2 vs app/models/extface/device.rb in extface-0.4.3a
- old
+ new
@@ -31,11 +31,13 @@
driver_class::NAME if driver_class
end
def session(description = nil)
job = jobs.create!(description: description)
- Thread.new do
+ job.thread = Thread.new do
+ Thread.current[:extface_job] = job.id
+ ActiveRecord::Base.establish_connection unless ActiveRecord::Base.connection.active?
begin
raise 'No driver configured' unless driver.present?
if driver.set_job(job)
yield driver
job.complete!
@@ -47,25 +49,13 @@
e.backtrace.each do |line|
p line
end
job.failed! e.message
ensure
- ActiveRecord::Base.connection.close
+ ActiveRecord::Base.connection.close unless Thread.list.select{ |t| t[:extface_job].present? }.many?
end
end
job
end
-
- #initial billing module fiscalization support
- def fiscalize(billing_account, detailed = false)
-
- driver.sale_and_pay_items_session(
- [].tap() do |payments|
- billing_account.payments.each do |payment|
- payments << Extface::Driver::Base::Fiscal::SaleItem.new(price: payment.value.to_f, text1: payment.description)
- end
- end
- ) if billing_account.instance_of?(Billing::Bill) && billing_account.valid?
-
- end
+
end
end