~singpolyma/jmp-pay

ref: 7c438f83822c6a2f41da32b93bbaa48203f0932b jmp-pay/lib/blather_notify.rb -rw-r--r-- 501 bytes
7c438f83Stephen Paul Weber Notify customer when renewal fails due to low balance 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

require "blather/client/dsl"
require "timeout"

module BlatherNotify
	extend Blather::DSL

	@ready = Queue.new

	when_ready { @ready << :ready }

	def self.start(jid, password)
		# workqueue_count MUST be 0 or else Blather uses threads!
		setup(jid, password, nil, nil, nil, nil, workqueue_count: 0)

		EM.error_handler { |e| warn e.message }
		Thread.new do
			EM.run do
				client.run
			end
		end

		at_exit { shutdown }

		Timeout.timeout(5) { @ready.pop }
	end
end