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

feat: Implement a generic task scheduler #653

Merged
merged 4 commits into from
Dec 16, 2024

Conversation

pacampbell
Copy link
Collaborator

@pacampbell pacampbell commented Dec 7, 2024

Implemented a light weight mechanism for scheduling recurring tasks. This can be used to implement, hourly, daily or weekly resets. There is also an intention to use the mechanism to check for seasonal events and turn on/off depending on the date.

Added example of a weekly reset for Epitaph Weekly rewards.

Checklist:

  • The project compiles
  • The PR targets develop branch

Copy link
Collaborator

@alborrajo alborrajo left a comment

Choose a reason for hiding this comment

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

Next stop: Implement craft timers

Arrowgene.Ddon.GameServer/Tasks/DailyTask.cs Show resolved Hide resolved

public override long NextTimestamp()
{
return new DateTimeOffset(DateTime.Now.AddHours(1)).ToUnixTimeSeconds();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I might need to be more careful with this. A long running server, this hour reset will eventually time drift. I might need to be more explicit and make it move to the next hour on the exact amount.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Be careful with that, not in the hourly task, but in the daily/weekly ones, as hour changes such as daylight savings means that the time different wont be the exact same

Copy link
Collaborator Author

@pacampbell pacampbell Dec 7, 2024

Choose a reason for hiding this comment

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

According to the MSDN, if we use DateTime using Now, it will account for DST based on that machines settings (needs automatic DST enabled on that machine). Will need to look and see how that can be utilized for future dates.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Japan doesn't do DST, so there's an argument that not respecting it is part of the original vision. :^)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This one is also interesting as it can be interpreted two ways. Does this mean "I always want to trigger this on the hour" or "I always want to trigger this after 60 minutes passes".

Copy link
Collaborator

Choose a reason for hiding this comment

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

With hours we're not going to have problems if we use AddHour or we add to the unix timestamp 60 * 60 * 1000. The problem is the daily task, which with DST it would be not 24 hours but 23/25 hours

@pacampbell pacampbell force-pushed the task_scheduling branch 6 times, most recently from de460c9 to 22b5634 Compare December 14, 2024 00:32
@pacampbell pacampbell requested a review from alborrajo December 14, 2024 00:33
Implemented a light weight mechanism for scheduling recurring tasks.
This can be used to implement, hourly, daily or weekly resets. There is
also an intention to use the mechanism to check for seasonal events and
turn on/off depending on the date.
- Treat the lowest server id as the head server.
- Head server runs the timer task
- When timer task fires, if individual channel actions are required, use
  the RPC manager to send an internal message.
- Update the EpitaphWeeklyReward task to send a message to all channels.
- Update migration values
- Move current hourly task implementation to NextTimeAmountTask
- Implemented a new hourly task which occurs wgen transitioning from x:59
  to y:00.
Enabled weekly reset as the default setting.
@pacampbell pacampbell merged commit a1f9c33 into sebastian-heinz:develop Dec 16, 2024
1 check passed
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