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

Add property to calculate and expose next run time of routine. #463

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adambirds
Copy link
Contributor

@adambirds adambirds commented Jul 27, 2024

Description

This PR adds a property next_run that calculates the next run time for the routine to the Routine class so that this can be exposed and used in other commands etc.

I have tested this on my own production twitch bot by installing from git and it works great.

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes. - couldn't find where to add the property. maybe auto generated from doc strings??
    • I have updated the changelog with a quick recap of my changes. - not sure which version number i would add it under.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)
  • I have read and agree to the Developer Certificate of Origin for this contribution

twitchio/ext/eventsub/models.py Outdated Show resolved Hide resolved
twitchio/ext/routines/__init__.py Show resolved Hide resolved
@adambirds
Copy link
Contributor Author

Is this able to be merged now? I have had this running for a few weeks now without an issue by installing direct from my branch but would be good to get merged.

@adambirds
Copy link
Contributor Author

@chillymosh can this be merged?

@EvieePy
Copy link
Member

EvieePy commented Sep 1, 2024

@chillymosh can this be merged?

I will test it now

@EvieePy
Copy link
Member

EvieePy commented Sep 1, 2024

Ideally this would be a method, not a property. Logic after some testing works fine though

@@ -330,6 +330,22 @@ def start_time(self) -> Optional[datetime.datetime]:
"""
return self._start_time

@property
def next_run(self) -> Optional[datetime.datetime]:
Copy link
Member

Choose a reason for hiding this comment

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

Not sure why it's optional? It doesn't appear the return would ever be optional

if next_run < now:
next_run = now + datetime.timedelta(seconds=self._delta)

return next_run
Copy link
Member

Choose a reason for hiding this comment

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

I'll have to check but this looks like it may have potential for next_run to never be defined.

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