Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented event steam #8

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Implemented event steam #8

wants to merge 8 commits into from

Conversation

RomanovSci
Copy link
Member

Signed-off-by: Roman Bylbas [email protected]

Summary

Implemented event steam

Checklist

  • Code is properly formatted
  • All commits are signed
  • Tests included/updated or not needed
  • Documentation (manuals or wiki) has been updated or is not required

Signed-off-by: Roman Bylbas <[email protected]>
@RomanovSci RomanovSci self-assigned this Dec 3, 2021
Roman Bylbas added 2 commits December 3, 2021 20:13
Signed-off-by: Roman Bylbas <[email protected]>

private ?string $name = null;

private ?array $data = null;
Copy link
Member

Choose a reason for hiding this comment

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

@RomanovSci we need to add typing here. I guess, the most convenient way would be to have event-specific event classes. The parsing could be moved to the EventStream.

Note, that events include the standard Casper types inside of them.

}
);

$es->connect(\Casper\EventStream\EventSource::EVENT_TYPE_MAIN);
Copy link
Member

Choose a reason for hiding this comment

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

The API is a bit confusing here:

  1. We create an EventSource object and connect it to event source, which isn't logical thus isn't intuitive
  2. We check if event id is not null, why? If that's part of the logic it should be handled by the library

Separatelly, we should provide possibility to start from the predefined event id, which could be passed in the event stream URL in the start_from parameter.

Note, the following possible usage:

$nodeUrl = 'http://localhost:9999';
$streamPath = \Casper\EventStream\EventSource::EVENT_TYPE_MAIN;
$startFromEvent = 12345;

$stream = new Casper\EventStream($nodeUrl, $streamPath, $startFromEvent);
$es->onEvent(
   function (\Casper\EventStream\DeployProcessedEvent $event) {
       echo json_encode($event->getDeployHeader()->getHash()) . "\n";
   }
);

$stream->listen();

Copy link
Member Author

Choose a reason for hiding this comment

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

Regarding 2.
We just show how we can use abort() method

$this->url = $url;
}

public function onMessage(callable $callback): void
Copy link
Member

Choose a reason for hiding this comment

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

onEvent would be a better name

($this->onMessage)($event);
}
} catch (\Exception $_) {
}
Copy link
Member

Choose a reason for hiding this comment

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

Why emtpy catch?

/**
* @throws \Exception
*/
public function connect(string $eventsType, int $startFrom = 0): void
Copy link
Member

@ihor ihor Jun 29, 2022

Choose a reason for hiding this comment

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

  1. $startFrom isn't used anywhere
  2. A better name would be listen

This function offers a blocking event processing. I guess it would be nice to offer an async interface. This way a consumer could subscribe to several event streams simultaneously and process all the events at once if needed. With the current approach it's not possible to process let's say main event stream and the deploys one.

Copy link
Member

@ihor ihor left a comment

Choose a reason for hiding this comment

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

@RomanovSci please check my comments

Signed-off-by: Roman Bylbas <[email protected]>
@mrkara mrkara requested a review from ihor July 24, 2023 22:46
@mrkara
Copy link
Member

mrkara commented Jul 24, 2023

@RomanovSci It looks like we have a small conflict on the README file. Could you please take a look?

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