lib/sapos/print/printer.rb in sapos-print-1.0.9 vs lib/sapos/print/printer.rb in sapos-print-1.0.10
- old
+ new
@@ -8,15 +8,22 @@
end
def print(args = {})
raw_message = args[:document]
- log_text = "id=#{args[:id]},doc=#{args[:document_number]},control=#{args[:print_control] ? "SI" : "NO"}\t"
+ log_text = "id=#{args[:id]},doc=#{args[:document_number]},control=#{args[:print_control] ? "SI" : "NO"},cache=0\t"
filename = "#{args[:document_number]}.print" if args[:document_number]
filename = SecureRandom.hex if filename.nil?
result = false
raw = raw_message.force_encoding("UTF-8")
+ msgid = args[:id]
+ if @config.duplicate_control? && @config.cache.include?(msgid)
+ log_text += " => DUPLICADO (DC)"
+ log_text.gsub!("cache=0", "cache=#{@config.cache.size}")
+ puts log_text
+ return true
+ end
begin
if args[:print_control] && args[:document_number]
print_dir = File.join(Sapos::Print.app_directory, 'print')
FileUtils.mkdir_p print_dir unless File.exists?(print_dir)
@@ -37,19 +44,23 @@
result = send_to_printer({file: filename})
File.delete(filename) if File.exists?(filename)
#puts "Result: #{result}"
log_text += " => OK"
end
+ if @config.duplicate_control?
+ @config.cache << msgid
+ @config.cache.shift if @config.cache.size > 30
+ log_text.gsub!("cache=0", "cache=#{@config.cache.size}")
+ end
puts log_text
rescue => e
puts "#{e.message}"
self.errors = e.message
result = false
ensure
#File.delete(filename) if File.exists?(filename)
return result
- end
-
+ end
end
def data(raw_message)
case @config.interface
when 'text'
\ No newline at end of file