From 11d74a50a065eabd59f5b2b40c0b09dba1fbc0a1 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Wed, 4 Sep 2024 13:05:32 +0800 Subject: [PATCH] feat: import pending tx by worker Signed-off-by: Miles Zhang --- app/workers/import_pending_tx_worker.rb | 5 ++++- config/sidekiq.yml | 1 + lib/websocket.rb | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/workers/import_pending_tx_worker.rb b/app/workers/import_pending_tx_worker.rb index 21db2e3f8..c447d4c8c 100644 --- a/app/workers/import_pending_tx_worker.rb +++ b/app/workers/import_pending_tx_worker.rb @@ -4,7 +4,10 @@ class ImportPendingTxWorker sidekiq_options retry: 0, queue: "pending_tx" def perform(data) - if CkbTransaction.tx_committed.find_by(tx_hash: data["transaction"]["hash"]) + committed_tx = CkbTransaction.tx_committed.find_by(tx_hash: data["transaction"]["hash"]) + if committed_tx && committed_tx.confirmation_time.nil? + confirmation_time = committed_tx.block_timestamp - data["timestamp"].hex + committed_tx.update(confirmation_time:) else CkbSync::Transactions.new([data]).import end diff --git a/config/sidekiq.yml b/config/sidekiq.yml index 226b22ba6..eb0df0b76 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -1,6 +1,7 @@ --- :concurrency: 5 :queues: + - pending_tx - critical - default - bitcoin diff --git a/lib/websocket.rb b/lib/websocket.rb index 65601e8db..7d124ed41 100644 --- a/lib/websocket.rb +++ b/lib/websocket.rb @@ -64,6 +64,7 @@ def subscribe(connection, topic) res = message.to_h if res[:method] == "subscribe" data = JSON.parse res[:params][:result] + ImportPendingTxWorker.perform_async(data) end end end