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

ENH: Optional Timezone #147

Merged
merged 34 commits into from
Nov 27, 2022
Merged

ENH: Optional Timezone #147

merged 34 commits into from
Nov 27, 2022

Conversation

Miksus
Copy link
Owner

@Miksus Miksus commented Nov 19, 2022

This PR implements custom timezones and custom time measurement function (for testing).

Set the timezone:

from rocketry import Rocketry
import pytz

app = Rocketry(timezone=pytz.timezone("Europe/Helsinki"))

Set the time:

def fix_time(dt):
    "Get new time measurement function"
    start_time = time.time()
    def get_time():
        sec_since_start = time.time() - start_time
        return dt.timestamp() + sec_since_start
    return get_time

app = Rocketry(fime_func=fix_time("2014-04-31 10:00:00"))

Other changes:

  • Start, end and runtime are passed as epoch to task log repos
  • last_run, last_success etc. are not in the JSON representation of a task anymore due to limitations in Pydantic.

Further Idea

Perhaps in the future we could have something like:

with app.test_time("2022-04-31 10:00:00"):
    app.start()

Not sure.

@codecov-commenter
Copy link

codecov-commenter commented Nov 20, 2022

Codecov Report

Base: 94.90% // Head: 95.20% // Increases project coverage by +0.29% 🎉

Coverage data is based on head (c9480a9) compared to base (8d3ab8a).
Patch coverage: 98.36% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #147      +/-   ##
==========================================
+ Coverage   94.90%   95.20%   +0.29%     
==========================================
  Files          80       80              
  Lines        4515     4630     +115     
==========================================
+ Hits         4285     4408     +123     
+ Misses        230      222       -8     
Impacted Files Coverage Δ
rocketry/core/time/utils.py 94.73% <85.71%> (-5.27%) ⬇️
rocketry/session.py 98.17% <97.43%> (+2.28%) ⬆️
rocketry/core/task.py 92.17% <98.64%> (+0.98%) ⬆️
rocketry/conditions/api.py 98.38% <100.00%> (ø)
rocketry/conditions/meta.py 93.87% <100.00%> (-1.68%) ⬇️
rocketry/conditions/scheduler.py 100.00% <100.00%> (ø)
rocketry/conditions/task/task.py 93.87% <100.00%> (ø)
rocketry/conditions/task/utils.py 90.12% <100.00%> (ø)
rocketry/conditions/time.py 95.23% <100.00%> (+0.50%) ⬆️
rocketry/core/log/adapter.py 100.00% <100.00%> (ø)
... and 7 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

New config option "time_func" and also now the custom time should be
propagated to processes as well. Required wrapping the logger method
for creating log records.
@Miksus Miksus added enhancement New feature or request core Relates to the core functionalities (ie. base classes) labels Nov 27, 2022
@Miksus Miksus merged commit bf54550 into master Nov 27, 2022
@Miksus Miksus deleted the dev/optional_timezone branch November 27, 2022 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Relates to the core functionalities (ie. base classes) enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants