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

Issue/#771 send broadcast info to rabbitmq #779

Merged

Conversation

Askaholic
Copy link
Collaborator

@Askaholic Askaholic commented Apr 21, 2021

I refactored the broadcasting logic to its own service which now also posts the broadcast messages to rabbitmq. I stuck with posting them to the same exchange as the gameResults for now, but I'd be interested to hear other peoples opinions on whether that makes sense or it should get its own exchange. The 3 part routing key is a little weird since there will never be any success states other than "success" and the CRUD operation will always be "update" and there is no real clear way to specify that the message is a broadcast.

I also decided to aggregate all of the game info into a single message just like it is sent during login. Maybe we should take the opportunity to differentiate between "game_info" messages that represent a single game and "game_info" messages that have a "games" sub-list. Maybe call it "game_list_info", or just get rid of the single game version entirely. I think getting rid of the single game version makes a lot of sense as it would maintain consistency with how the other broadcasted info messages look.

Closes #771

@codecov
Copy link

codecov bot commented Apr 21, 2021

Codecov Report

Merging #779 (65207fb) into develop (5dba1f9) will decrease coverage by 0.13%.
The diff coverage is 98.59%.

Impacted Files Coverage Δ
server/timing/timer.py 79.36% <85.71%> (-6.60%) ⬇️
server/__init__.py 91.02% <100.00%> (-1.98%) ⬇️
server/broadcast_service.py 100.00% <100.00%> (ø)
server/config.py 100.00% <100.00%> (ø)
server/game_service.py 99.02% <100.00%> (+<0.01%) ⬆️
server/lobbyconnection.py 93.96% <100.00%> (ø)
server/message_queue_service.py 97.82% <100.00%> (ø)
server/player_service.py 99.20% <100.00%> (-0.01%) ⬇️
server/timing/__init__.py 100.00% <100.00%> (ø)
... and 3 more

Copy link
Member

@Brutus5000 Brutus5000 left a comment

Choose a reason for hiding this comment

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

I don't understand much about the structure of the Python server.
So my first question is: Why do you need a "BroadcastService" and does it really do what the name implies?

It looks like the broadcast service is not only responsible for broadcasting but also responsible for fetching the dirty games and also clearing them. For me this looks like a violation of separation of concerns.

If the broadcast service follows it's name it should be responsible for broadcasting messages and the services calling it are responsible for delivering the data. If that's not the case, maybe a different name would be better.

In any scenario the gameService (?) should be responsible for clearing it's own dirtylist.
Whether it pushes the list before cleaning it to the broadcast service or whether it offers a "transactional" method for querying and cleaning the dirty games list to be called by the broadcast service doesn't matter.

@Askaholic
Copy link
Collaborator Author

Why do you need a "BroadcastService"

Mostly this is a refactor of the broadcast loop that used to be part of ServerInstance. It didn't really feel right to keep adding to the code where it was.

whether it offers a "transactional" method for querying and cleaning the dirty games list to be called by the broadcast service

I could do that. That's probably nicer than accessing the member variables directly. There's also this bit of code which IMO doesn't belong there either

if game.state == GameState.ENDED:
    self.game_service.remove_game(game)

but I'd rather not mess with refactoring that ATM since it's out of the scope of this PR and getting it wrong could cause all sorts of horrible stuff like ghost games.

@Askaholic Askaholic force-pushed the issue/#771-broadcast-to-rabbitmq branch from c08b608 to 2cd7835 Compare April 23, 2021 18:31
@Askaholic Askaholic marked this pull request as ready for review April 23, 2021 18:36
@Askaholic Askaholic force-pushed the issue/#771-broadcast-to-rabbitmq branch from 2cd7835 to 480d2a3 Compare April 25, 2021 18:48
Copy link
Contributor

@eoinnoble eoinnoble left a comment

Choose a reason for hiding this comment

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

This is way over my head in most respects but certainly nothing glaringly wrong from what I can see.

)
self._logger.debug("Broadcast service initialized")

async def report_dirties(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

As someone new to the code base I'd love a brief docstring here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How about that?

server/broadcast_service.py Outdated Show resolved Hide resolved
server/game_service.py Outdated Show resolved Hide resolved
server/timing/timer.py Outdated Show resolved Hide resolved
Comment on lines +59 to +65
# The reference to the ServerInstance needs to be established later
service = BroadcastService(
None,
message_queue_service,
game_service,
player_service,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# The reference to the ServerInstance needs to be established later
service = BroadcastService(
None,
message_queue_service,
game_service,
player_service,
)
service = BroadcastService(
None, # Reference to the Server instance needs to be established later
message_queue_service,
game_service,
player_service,
)

tests/integration_tests/conftest.py Outdated Show resolved Hide resolved
@Askaholic Askaholic force-pushed the issue/#771-broadcast-to-rabbitmq branch from 480d2a3 to eb12ec7 Compare April 27, 2021 22:13
Copy link
Contributor

@0x647262 0x647262 left a comment

Choose a reason for hiding this comment

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

LGTM!

@Askaholic Askaholic force-pushed the issue/#771-broadcast-to-rabbitmq branch 3 times, most recently from 5e4fdd0 to b01e871 Compare May 3, 2021 07:26
@Askaholic Askaholic force-pushed the issue/#771-broadcast-to-rabbitmq branch from b01e871 to ada7ee6 Compare May 3, 2021 20:06
@Askaholic Askaholic force-pushed the issue/#771-broadcast-to-rabbitmq branch from ada7ee6 to 65207fb Compare May 3, 2021 20:57
@Askaholic Askaholic merged commit 38cc8fe into FAForever:develop May 3, 2021
@Askaholic Askaholic deleted the issue/#771-broadcast-to-rabbitmq branch May 3, 2021 22:05
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.

Add broadcasted info updates to RabbitMQ
4 participants