Skip to content

Commit

Permalink
feat: import pending tx by worker
Browse files Browse the repository at this point in the history
Signed-off-by: Miles Zhang <mingchang555@hotmail.com>
  • Loading branch information
zmcNotafraid committed Sep 5, 2024
1 parent a8450d1 commit 11d74a5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/workers/import_pending_tx_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/sidekiq.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
:concurrency: 5
:queues:
- pending_tx
- critical
- default
- bitcoin
Expand Down
1 change: 1 addition & 0 deletions lib/websocket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11d74a5

Please sign in to comment.