Class: Billing::IssuePrintDoc

Inherits:
Object
  • Object
show all
Extended by:
Resque::Plugins::ExtfaceLonelyDevice
Defined in:
app/jobs/billing/issue_print_doc.rb

Constant Summary

Constants included from Resque::Plugins::ExtfaceLonelyDevice

Resque::Plugins::ExtfaceLonelyDevice::LOCK_TIMEOUT

Class Method Summary collapse

Methods included from Resque::Plugins::ExtfaceLonelyDevice

around_perform, before_perform, can_lock_queue?, lock_timeout, redis_key, reenqueue, requeue_interval, unlock_queue

Class Method Details

.perform(bill_id) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/jobs/billing/issue_print_doc.rb', line 76

def self.perform(bill_id)
  bill = Bill.find(bill_id)
  qname = "extface_#{bill.print_job.device_id}"
  wjs = Resque::Worker.working.find_all{ |w| w.job && w.job['queue'] == qname }
  
  p "############################"
  p "d: #{bill.print_job.device_id} Issue Print Doc ##{bill_id}, job: #{bill.print_job_id}, wjs: #{wjs.inspect}"
  p "____________________________"
  p "active jobs: #{bill.print_job.device.jobs.active.count}"
  

  bill.print_job.runtime do |s|
    return unless bill.printable?
    s.notify "Print Doc Start"
    s.print "******************************\r\n*"
    s.print "Bill ##{bill.number}".center(28)
    s.print "*\r\n******************************\r\n"
    s.print "------------------------------\r\n"
    
    bill.charges.each do |charge|
      s.print "#{charge.name.ljust(22)} #{charge.value.to_s.rjust(7)}\r\n"
    end
    s.print "-----------\r\n".rjust(32)
    s.print "#{bill.total}\r\n".rjust(32)
    
    # s.print "..............................\r\n"
    # bill.payments.each do |payment|
      # s.print "#{payment.payment_type.name.humanize}\r\n"
    # end
    
    s.print "\r\n"
    s.print "------------------------------\r\n"
    s.print Time.now.strftime("Printed on %m/%d/%Y %T\r\n").rjust(32)
    s.print "\r\n\r\n\r\n"
    s.notify "Print Doc End"
  end
rescue Resque::TermException
  reenqueue(bill_id)
end

.redis_key(bill_id) ⇒ Object



72
73
74
# File 'app/jobs/billing/issue_print_doc.rb', line 72

def self.redis_key(bill_id)
  "extface_#{Bill.find(bill_id).print_job.device_id}"
end