~singpolyma/jmp-pay

dbfef4485da330373ed7632777f3d0dd9e9137b0 — Stephen Paul Weber 2 years ago 42ba844
better healthcheck log
1 files changed, 4 insertions(+), 3 deletions(-)

M bin/process_pending_btc_transactions
M bin/process_pending_btc_transactions => bin/process_pending_btc_transactions +4 -3
@@ 32,7 32,7 @@ CONFIG =
	.new(safe: Dhall::Coder::JSON_LIKE + [Symbol, Proc])
	.load(ARGV[0], transform_keys: :to_sym)

Net::HTTP.post_form(URI("#{CONFIG[:healthchecks_url]}/start"), {})
Net::HTTP.post(URI("#{CONFIG[:healthchecks_url]}/start"), "")

REDIS = Redis.new
ELECTRUM = Electrum.new(**CONFIG[:electrum])


@@ 243,7 243,7 @@ class Customer
	end
end

REDIS.hgetall("pending_btc_transactions").each do |(txid, customer_id)|
done = REDIS.hgetall("pending_btc_transactions").map do |(txid, customer_id)|
	tx_hash, address = txid.split("/", 2)
	transaction = ELECTRUM.gettransaction(tx_hash)
	next unless transaction.confirmations >= CONFIG[:required_confirmations]


@@ 259,10 259,11 @@ REDIS.hgetall("pending_btc_transactions").each do |(txid, customer_id)|
			customer.add_btc_credit(txid, btc, amount)
			customer.plan.activate_any_pending_plan!
			REDIS.hdel("pending_btc_transactions", txid)
			txid
		else
			warn "No plan for #{customer_id} cannot save #{txid}"
		end
	end
end

Net::HTTP.post_form(URI(CONFIG[:healthchecks_url].to_s), {})
Net::HTTP.post(URI(CONFIG[:healthchecks_url].to_s), done.compact.join("\n"))