Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions twitchio/ext/routines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""Calculate and return the next run time of the routine."""
now = datetime.datetime.now(datetime.timezone.utc)

if self._time:
next_run = self._time + datetime.timedelta(days=self._completed_loops)
if next_run < now:
next_run += datetime.timedelta(days=1)
elif self._delta:
next_run = self._start_time + datetime.timedelta(seconds=self._delta * (self._completed_loops + 1))
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.


def _can_be_cancelled(self) -> bool:
return self._task and not self._task.done()

Expand Down