From a72bad4c79b63fe94cb298c31e06f97348d24ae1 Mon Sep 17 00:00:00 2001 From: Emmo00 Date: Fri, 23 Jan 2026 15:56:24 +0100 Subject: [PATCH 1/2] refactor: implement retry logic for Streamr stream retrieval in UI and core modules --- src/lib/core/streamr/index.ts | 12 ++++-------- src/lib/core/streamr/ui.ts | 3 ++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/lib/core/streamr/index.ts b/src/lib/core/streamr/index.ts index 6bf7b42..4a4856a 100644 --- a/src/lib/core/streamr/index.ts +++ b/src/lib/core/streamr/index.ts @@ -29,12 +29,12 @@ export default class implements Hooks { await retry( () => this.publishPendingTransactionsToStreamr(STREAMR_STREAM_ID, pendingTransactions), 3, - 2000 + 2000, ); } } }, - { name: "streamr-publish-pending-transactions", noOverlap: true } + { name: "streamr-publish-pending-transactions", noOverlap: true }, ); console.log("Streamr cron job registered."); @@ -53,14 +53,10 @@ export default class implements Hooks { }); try { - const stream = await retry( - () => streamrClient.getStream(STREAMR_STREAM_ID!), - 3, - 2000 - ); + const stream = await retry(() => streamrClient.getStream(STREAMR_STREAM_ID!), 3, 2000); await new Promise((resolve) => setTimeout(resolve, 2000)); - + const batchPayload = buildBatchPayload(pendingTransactions); await stream.publish(batchPayload); diff --git a/src/lib/core/streamr/ui.ts b/src/lib/core/streamr/ui.ts index 9ceaa00..6204318 100644 --- a/src/lib/core/streamr/ui.ts +++ b/src/lib/core/streamr/ui.ts @@ -140,8 +140,9 @@ export default class implements UIHooks { }); try { - const stream = await streamrClient.getStream(streamId); + const stream = await retry(() => streamrClient.getStream(streamId), 3, 2000); const batchPayload = buildBatchPayload(pendingTransactions); + await new Promise((resolve) => setTimeout(resolve, 2000)); await stream.publish(batchPayload); } finally { await streamrClient.destroy(); From 5c3b507b28907b05efeef338cbd2526c474e7b5a Mon Sep 17 00:00:00 2001 From: Emmo00 Date: Fri, 23 Jan 2026 16:36:06 +0100 Subject: [PATCH 2/2] refactor: enhance logging for Streamr connection and publishing process in core and UI modules --- src/lib/core/streamr/index.ts | 6 ++++-- src/lib/core/streamr/ui.ts | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib/core/streamr/index.ts b/src/lib/core/streamr/index.ts index 4a4856a..06bb2cf 100644 --- a/src/lib/core/streamr/index.ts +++ b/src/lib/core/streamr/index.ts @@ -53,17 +53,19 @@ export default class implements Hooks { }); try { + console.log(`[streamr] Connecting to ${STREAMR_STREAM_ID}...`); const stream = await retry(() => streamrClient.getStream(STREAMR_STREAM_ID!), 3, 2000); await new Promise((resolve) => setTimeout(resolve, 2000)); + console.log(`[streamr] Connected. Publishing ${pendingTransactions.length} transactions...`); const batchPayload = buildBatchPayload(pendingTransactions); await stream.publish(batchPayload); + console.log(`[streamr] Published ${pendingTransactions.length} transactions to stream ${STREAMR_STREAM_ID}`); await new Promise((resolve) => setTimeout(resolve, 2000)); } catch (error) { - console.error(`Failed to publish to Streamr: ${(error as Error).message}`); - throw error; + console.error(`[streamr] Error publishing to Streamr:`, error); } finally { // destroy the client to free resources await streamrClient.destroy(); diff --git a/src/lib/core/streamr/ui.ts b/src/lib/core/streamr/ui.ts index 6204318..be89677 100644 --- a/src/lib/core/streamr/ui.ts +++ b/src/lib/core/streamr/ui.ts @@ -140,10 +140,17 @@ export default class implements UIHooks { }); try { + console.log(`[streamr-ui] Connecting to ${streamId}...`); const stream = await retry(() => streamrClient.getStream(streamId), 3, 2000); + + console.log(`[streamr-ui] Connected. Publishing ${pendingTransactions.length} transactions...`); const batchPayload = buildBatchPayload(pendingTransactions); + await new Promise((resolve) => setTimeout(resolve, 2000)); await stream.publish(batchPayload); + console.log(`[streamr-ui] Published ${pendingTransactions.length} transactions to stream ${streamId}`); + } catch (error) { + console.error(`[streamr-ui] Error publishing to Streamr:`, error); } finally { await streamrClient.destroy(); }