Skip to content

feat(event streaming): configurable worker path, use SharedWorker#2080

Merged
shamardy merged 12 commits intodevfrom
fix-config-worker-file
Mar 7, 2024
Merged

feat(event streaming): configurable worker path, use SharedWorker#2080
shamardy merged 12 commits intodevfrom
fix-config-worker-file

Conversation

@shamardy
Copy link
Copy Markdown
Collaborator

@shamardy shamardy commented Mar 5, 2024

This PR allows any worker path to be used instead of hardcoded worker.js file. The worker path can be specified using worker_path in event_stream_configuration, if not specified worker.js will be used as default. Example:

"event_stream_configuration": {
    "access_control_allow_origin": "*",
    "active_events": {
      "NETWORK": { "stream_interval_seconds": 1.5 }
    },
    "worker_path": "index.js" // This can be added in wasm only configuration
}


let worker = web_sys::Worker::new("worker.js").expect("Missing worker.js");
let worker_path = config.worker_path.as_deref().unwrap_or(DEFAULT_WORKER_PATH);
let worker = web_sys::Worker::new(worker_path).expect("Missing worker.js");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might not be "worker.js".

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was already fixing this. Done :)

Copy link
Copy Markdown

@borngraced borngraced Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might have another worker.js that serves a diff purpose In the future so why not make it balance_streaming_worker.js as default ?

Also, worker.js is a very basic worker that's not doing much and we might have a more complex worker in the future

Copy link
Copy Markdown
Collaborator Author

@shamardy shamardy Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make it balance_streaming_worker.js if agreed by @onur-ozkan and they would have to fix it in the react-komodefi-wasm branch

Also, worker.js is a very basic worker that's doing much and we might have a more complex worker in the future

Can you please elaborate on this @borngraced ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should get some feedback from the frontend devs. They may prefer to handle all the events from single worker file by filtering the incoming data.

It's still a single worker file for event streaming

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they requested multiple workers in the future we can do it in another PR.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the current worker script used for balance streaming is only logging the messages to the console..

It's just for demonstration, it doesn't have to be that way obviously.

You can handle all kinds of operations from a single worker file by filtering the incoming payload. As I mentioned, this preference should be defined by the frontend developers not by us as this affects their project structure directly.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still a single worker file for event streaming

I am aware of it, I meant event streaming + different tasks on workers

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am aware of it, I meant event streaming + different tasks on workers

In this case they can change the config I guess.

@shamardy
Copy link
Copy Markdown
Collaborator Author

shamardy commented Mar 5, 2024

@smk762 @gcharang after this is merged to dev, worker.js here https://github.com/KomodoPlatform/react-komodefi-wasm/blob/streaming/worker.js should be renamed to event_streaming_worker.js

borngraced
borngraced previously approved these changes Mar 6, 2024
@shamardy
Copy link
Copy Markdown
Collaborator Author

shamardy commented Mar 7, 2024

@smk762 @gcharang I changed the worker type to be a shared worker, so the script in event_streaming_worker.js should be changed to the following

// use chrome://inspect in Chrome to debug the worker
// use about:debugging in Firefox to debug the worker
self.onconnect = function(event) {
    var port = event.ports[0];

    console.log('A new connection to the shared worker has been successfully established.');

    port.onmessage = function(e) {
        console.log(e.data);
    };
};

Shared workers debugging can be accessed from chrome://inspect in chrome or about:debugging in Firefox, from there you can navigate to shared workers and choose event_streaming_worker.js and see the console logs.

Copy link
Copy Markdown

@onur-ozkan onur-ozkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

Copy link
Copy Markdown

@borngraced borngraced left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to this doc, and usage of shared worker..do you think we need it here just stick to dedicated worker without much stuffs going on in this code.

Copy link
Copy Markdown

@borngraced borngraced left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🔥

@shamardy
Copy link
Copy Markdown
Collaborator Author

shamardy commented Mar 7, 2024

according to this doc, and usage of shared worker..do you think we need it here just stick to dedicated worker without much stuffs going on in this code.

it was requested by @naezith since normal worker doesn't fit his needs in the flutter codebase. Plus, I think it's good to have event streaming worker shared and accessed from multiple contexts.

@shamardy shamardy changed the title feat(event streaming): make worker path configurable feat(event streaming): make worker path configurable and use shared worker Mar 7, 2024
@shamardy shamardy changed the title feat(event streaming): make worker path configurable and use shared worker feat(event streaming): make worker path configurable and use SharedWorker Mar 7, 2024
@shamardy shamardy changed the title feat(event streaming): make worker path configurable and use SharedWorker feat(event streaming): configurable worker path configurable, use SharedWorker Mar 7, 2024
@shamardy shamardy changed the title feat(event streaming): configurable worker path configurable, use SharedWorker feat(event streaming): configurable worker path, use SharedWorker Mar 7, 2024
@shamardy shamardy merged commit 10fe7fa into dev Mar 7, 2024
@shamardy shamardy deleted the fix-config-worker-file branch March 7, 2024 14:08
dimxy pushed a commit to dimxy/komodo-defi-framework that referenced this pull request Mar 13, 2024
* dev:
  feat(indexeddb): advanced cursor filtering impl (GLEECBTC#2066)
  update dockerhub destination repository (GLEECBTC#2082)
  feat(event streaming): configurable worker path, use SharedWorker (GLEECBTC#2080)
  fix(hd_tests): fix test_hd_utxo_tx_history unit test (GLEECBTC#2078)
  feat(network): improve efficiency of known peers handling (GLEECBTC#2074)
  feat(nft): enable eth with non fungible tokens (GLEECBTC#2049)
  feat(ETH transport & heartbeats): various enhancements/features (GLEECBTC#2058)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants