-
Notifications
You must be signed in to change notification settings - Fork 25
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
Feature - Background Queue Worker / Highscore #424
Conversation
Hi @jackbayliss, Thanks for taking on the work for this issue! The new scheduler container looks like a nice and flexible way to approach this, nice! I'm not sure exactly why the tests are failing, however I noticed that you made a change to the Dockerfile that uses the following.
To share some helpful context: when working on implementing the GitHub actions before I learned that GitHub actions have a restriction in that it doesn't support In order to fix this issue I added a step to the GitHub actions that strips out the original .github/workflows/run-tests-docker-compose.yml
So this might be the reason for why it's failing now since the string search and replace cannot find the original string anymore. Additionally with this
BTW as this is a WIP feature, feel free to disregard my comments if you've already looked into this! Just trying to give some context in case it helps! 😄 |
@lanedirt appreciate the heads up! Still quite a bit to do, but wanted to get the new container scheduler approach up just incase anyone wanted to work on the high score bit / get some feedback, but glad you think it works. It seems to work well so far locally, but hoping to continue and clear everything up at some point over the weekend / this week Thanks for the insight 😃 |
Tests are now fixed 🚀 🐛 I had setup the dev docker image, not the prod, have now sorted the prod image-- prod image was used by the actions. |
More WIP changes, PHP Stan has come up with an error due to using chunkbyId I believe, so I need to resolve that. but a good start for now- once I sort that we should be able to switch out the service to use the DB rather than calling it on the fly... which means we could then use pagination. |
caches highscore count, and adds it to nav
allows us to easily see the ranks
- adds highscore types enum - adds new highscore rank command that sorts out the ranks - changes service to return highscore - adds highscore rank to nav - Various caching - Switched custom paging to pagination built into Laravel
ensure ordered by rank, and cache by name.
@lanedirt This should finally be good for a bit of testing. It's using the DB and caching various bits so should be an overall improvement. One thing I noticed is PHPStan was having a issue with the The good thing about the schedule is, in future if there's thousands of users - it will call it every 5 minutes, but take as long as it needs to finish the command. But can always increase it in future. Side note, I've noticed the Still could do with some tests being added, but at least you can see it and how it works 😄 I've added a new Highscore Model, that uses a scope - this just means we can easily access the scope when using the model-- ie I may be unavailable for the new few days due to work commitments, so do feel free to make amends if it's urgent 👍🏻 |
Hi @jackbayliss, What can I say: awesome work, really cool! I can learn quite a few things from this 😄! Thanks for your persistence on implementing this feature. I’ll go through the changes in the coming days and test them in my local environment. I’ll also try testing it with a copy of the current main.ogamex.dev production database to see how it works with that dataset (around 150-200 users). I’ll let you know once I’ve had a chance to test & review it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jackbayliss,
Thanks again for your work on this. I tested it on my localhost and came across a few things. I also added some minor comments inline to the PR. Other than these things, the changes look good to me in terms of structure. 👍
- When I start the updated docker stack via
docker compose up -d
the scheduler container comes online, however I'm not seeing any highscores appear. The highscore list stays empty on my environment. I waited for 10+ minutes to ensure any cache should have been cleared. The scheduler docker container is not showing any errors, however I'm also not seeing any confirmation that the scheduler is running. Am I missing a step by any chance?
$ docker compose logs scheduler
scheduler-1 | [02-Nov-2024 13:56:12] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
scheduler-1 | [02-Nov-2024 13:56:12] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
scheduler-1 | [02-Nov-2024 13:56:12] NOTICE: fpm is running, pid 1
scheduler-1 | [02-Nov-2024 13:56:12] NOTICE: ready to handle connections
- When I manually run the artisan commands I do get contents on the highscore page. This looks pretty good, however with the production dataset of 200+ players the sort does not seem to work correctly. On page 2 where all players have a score of 0, suddenly on rank 200 I see two players with a positive score. This is what I see:
- I also noticed something in the paging that seems to be off. Page 1 shows ranks 1 - 102 for me. I would expect it to show ranks 1-100, for exactly 100 players per page.
- Question for new player registrations: when a new player creates an account, currently because of the 5 minute delay in cache they do not yet show up in the highscores and the highscore rank shows 0, screenshots below. The official game has a certain mechanism where if a new player creates an account they do show up immediately in the highscores with score "0", and they can see their actual rank also in the top menu above. Is it possible to integrate this logic into the new highscore system, i.e. when a new user creates their account they get an associated highscore record in the db where their rank is simply current last rank + 1, and all points set to 0, and caches are cleared?
Could you have a look at these comments? Thanks a lot! 🚀
@lanedirt Thanks! I'm not sure why the scheduler isn't working for you, did you a try a As for new registrations, we could use an observable to listen on user created, so whenever it's triggered it'll run the commands or as you say take the last max and add 1 I only had two users locally, I'll have to play with the factories to try and generate some fake scores to adjust the logic. As I don't have the users you do. Comments all look good, minor adjustments - thanks for looking into the Stan thing 🙂 |
Yes the --build seems to have done the trick. 👍 Good catch. Makes sense, as it probably used a cached build of the main Dockerfile which didn't had the entrypoint logic yet. Thanks! Now however when I run the
Do I need to make this file executable manually or is something missing from the Dockerfile logic? Because the user/group permissions seem to be fine. They are all set to
|
I'm not sure - I usually exec into the image and watch the log that way 😀 |
- alters user factory to match db fields - fixes php ignore lines to proper typing - adjusts querys to use `validRank` so its consistent - Adds observer to add highscore when user tech is created - adds whereHas to queries to ensure tech exists.
Most recent changes should have sorted your comments! I've made sure now when a user registers, they'll automatically get added to the highscore board. This hinges off the user tech model for now - but can easily change it to the user one. I felt the user tech model was better, as the PlayerService requires tech on the high score. I've altered the queries so it should now page correctly it was pulling 100 entries correctly, but the issue is some rankings were missing where the users didn't have tech etc.. at least that happened locally. Let me know if it's still not right for you? Not sure there's a factory to easy generate this. I've looked at the |
Hi @jackbayliss, Thanks for fixes! I just tested it again on my local environment however it looks like I'm still running into a few issues.
PS: if you want to add more test users to your local environment you should be able to do so by running the test suite locally with
|
@lanedirt Thanks! I'll check it out. I presume you did the production DB from fresh? ie copy it into the repo and ran a migration? |
Thanks! Yes correct, I started the test today with a fresh copy from production and then applied the migrations. I checked and there were no artifacts remaining from the previous test. |
@lanedirt Good shout! - It works as expected locally using the testing users. I've also rebuild the docker image and it works correctly for me on Windows just to double check - output of scheduler below : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Will merge the changes now and will then verify on main.ogamex.dev if everything works as expected. Major thanks for your work on this! 🚀
Awesome! Let me know if anything strange happens, I'll probably open an issue for some efficiency that could be made in the observer when I get chance. |
WIP for #417
php artisan schedule
command every minuteconsole.php
route, to pass in commands to run - example is in there for now-- will be removed.To do: