Skip to content

Commit

Permalink
0.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemanspiff2007 committed Aug 24, 2023
1 parent a58c1c0 commit a161d90
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 14 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/publish-pypi.yml
Expand Up @@ -9,13 +9,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ref: main
- name: Set up Python 3.8
uses: actions/setup-python@v2
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: '3.10'

- name: Install setuptools
run: |
Expand Down
6 changes: 3 additions & 3 deletions docs/requirements.txt
@@ -1,3 +1,3 @@
sphinx
sphinx_autodoc_typehints
sphinx_rtd_theme
sphinx == 7.2.3
sphinx-autodoc-typehints == 1.24.0
sphinx_rtd_theme == 1.3.0
3 changes: 3 additions & 0 deletions readme.md
Expand Up @@ -19,6 +19,9 @@ Easy Async Scheduler (or EAScheduler) is a lightweight asyncio scheduler with a

## Changelog

#### 0.1.10 (2023-08-24)
- Added option to add a callback to the job when the execution time changes

#### 0.1.9 (2023-07-19)
- Fix for days when the sun doesn't rise or set.
In that case the next date with a sunrise/sunset will be returned.
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Expand Up @@ -6,9 +6,9 @@ pytest >= 7.4, < 7.5
pytest-asyncio >= 0.21 , < 0.22

# Docs
sphinx == 6.2.1
sphinx-autodoc-typehints == 1.23.0
sphinx_rtd_theme == 1.2.2
sphinx == 7.2.3
sphinx-autodoc-typehints == 1.24.0
sphinx_rtd_theme == 1.3.0

# static checker
mypy >= 0.991
mypy >= 1.5.1
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -62,6 +62,7 @@ def load_req() -> typing.List[str]:
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Office/Business :: Scheduling"
],
Expand Down
2 changes: 1 addition & 1 deletion src/eascheduler/__version__.py
@@ -1 +1 @@
__version__ = '0.1.9'
__version__ = '0.1.10'
15 changes: 14 additions & 1 deletion src/eascheduler/jobs/job_base.py
@@ -1,7 +1,7 @@
from datetime import datetime
from datetime import time as dt_time
from datetime import timedelta
from typing import Optional, TYPE_CHECKING, Union
from typing import Optional, TYPE_CHECKING, Union, Callable, Any

from pendulum import DateTime, from_timestamp, instance
from pendulum import now as get_now
Expand All @@ -17,11 +17,16 @@

class ScheduledJobBase:
def __init__(self, parent: 'AsyncScheduler', func: ExecutorBase):
super().__init__()

self._func: ExecutorBase = func

# time when we run as a UTC timestamp
self._next_run: float = FAR_FUTURE

# callback that gets executed when the next run changes
self._next_run_callback: Optional[Callable[[ScheduledJobBase], Any]] = None

# If parent is set it's also the indication that the job is scheduled
self._parent: Optional['AsyncScheduler'] = parent

Expand All @@ -47,6 +52,10 @@ def _set_next_run(self, next_run: float):
self._next_run = next_run
self._parent.add_job(self)

# callback when we have a new timestamp
if (cb := self._next_run_callback) is not None:
cb(self)

def cancel(self):
"""Cancel the job."""
if self._parent is None:
Expand All @@ -60,6 +69,10 @@ def cancel(self):
self._parent = None
parent.remove_job(self)

# callback when we have a new timestamp
if (cb := self._next_run_callback) is not None:
cb(self)

def get_next_run(self) -> datetime:
"""Return the next execution timestamp."""
return from_timestamp(self._next_run, local_tz).naive()
Expand Down
1 change: 0 additions & 1 deletion src/eascheduler/jobs/job_countdown.py
Expand Up @@ -40,7 +40,6 @@ def reset(self):

now = get_now(UTC).timestamp()
self._set_next_run(now + self._expire)
self._parent.add_job(self)

def stop(self):
"""Stops the countdown so it can be started again with a call to reset"""
Expand Down
19 changes: 19 additions & 0 deletions tests/jobs/test_all_jobs.py
@@ -1,11 +1,13 @@
from inspect import getargs
from unittest.mock import Mock, call

import pytest

from eascheduler.errors import JobAlreadyCanceledException
from eascheduler.jobs import (
CountdownJob, DawnJob, DayOfWeekJob, DuskJob, OneTimeJob, ReoccurringJob, SunriseJob, SunsetJob
)
from eascheduler.schedulers import AsyncScheduler


@pytest.mark.parametrize(
Expand All @@ -29,3 +31,20 @@ def test_job_canceled(cls, name: str):
func(None)
else:
func()


@pytest.mark.parametrize(
'cls', (ReoccurringJob, DayOfWeekJob, CountdownJob, OneTimeJob, SunsetJob, SunriseJob, DuskJob, DawnJob))
async def test_callback(cls, async_scheduler: AsyncScheduler):

job = cls(async_scheduler, None)
job._next_run_callback = m = Mock()

m.assert_not_called()
job._set_next_run(300)
m.assert_called_with(job)

m.reset_mock()
m.assert_not_called()
job.cancel()
m.assert_called_with(job)

0 comments on commit a161d90

Please sign in to comment.