-
Notifications
You must be signed in to change notification settings - Fork 2
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
issue_105 #121
Merged
Merged
issue_105 #121
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
from datetime import datetime, timezone | ||
|
||
|
||
def datetime_utcnow(): | ||
# type: () -> datetime | ||
return datetime.now(timezone.utc) | ||
|
||
|
||
def utc_from_timestamp(timestamp): | ||
# type: (float) -> datetime | ||
return datetime.fromtimestamp(timestamp, timezone.utc) | ||
|
||
|
||
def naive_utcnow(): | ||
return datetime_utcnow().replace(tzinfo=None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,11 @@ | |
# under the License. | ||
# | ||
|
||
import datetime | ||
from datetime import datetime | ||
from typing import List | ||
|
||
from app import db | ||
from app.datetime import naive_utcnow | ||
|
||
from dateutil.relativedelta import relativedelta | ||
|
||
|
@@ -25,8 +26,8 @@ | |
from sqlalchemy import Integer | ||
from sqlalchemy import String | ||
from sqlalchemy import Table | ||
from sqlalchemy import func | ||
from sqlalchemy import text as Text | ||
from sqlalchemy import or_ | ||
from sqlalchemy import select | ||
from sqlalchemy.orm import DeclarativeBase | ||
from sqlalchemy.orm import Mapped | ||
|
@@ -108,9 +109,9 @@ | |
PropComparator.and_( | ||
or_( | ||
Incident.end_date.is_(None), | ||
Incident.end_date > datetime.datetime.now() | ||
Incident.end_date > naive_utcnow() | ||
), | ||
Incident.start_date <= datetime.datetime.now(), | ||
Incident.start_date <= naive_utcnow(), | ||
), | ||
), | ||
) | ||
|
@@ -171,8 +172,8 @@ | |
def calculate_sla(self): | ||
"""Calculate component availability on the month basis""" | ||
|
||
time_now = datetime.datetime.now() | ||
this_month_start = datetime.datetime(time_now.year, time_now.month, 1) | ||
time_now = naive_utcnow() | ||
this_month_start = datetime(time_now.year, time_now.month, 1) | ||
|
||
outages = [inc for inc in self.incidents | ||
if inc.impact == 3 and inc.end_date is not None] | ||
|
@@ -271,10 +272,11 @@ | |
__tablename__ = "incident" | ||
id = mapped_column(Integer, primary_key=True, index=True) | ||
text: Mapped[str] = mapped_column(String()) | ||
start_date: Mapped[datetime.datetime] = mapped_column( | ||
insert_default=func.now() | ||
start_date: Mapped[datetime] = mapped_column( | ||
db.DateTime, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is db.DateTime corect here? Before you used only one argument and now two There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is an explicit indication of the data type |
||
insert_default=Text("TIMEZONE('utc', now())") | ||
) | ||
end_date: Mapped[datetime.datetime] = mapped_column(nullable=True) | ||
end_date: Mapped[datetime] = mapped_column(nullable=True) | ||
impact: Mapped[int] = mapped_column(db.SmallInteger) | ||
# upgrade: system: Mapped[bool] = mapped_column(Boolean, default=False) | ||
system: Mapped[bool] = mapped_column(Boolean, default=False) | ||
|
@@ -298,9 +300,9 @@ | |
select(Incident).filter( | ||
or_( | ||
Incident.end_date.is_(None), | ||
Incident.end_date > datetime.datetime.now() | ||
Incident.end_date > naive_utcnow() | ||
), | ||
Incident.start_date <= datetime.datetime.now(), | ||
Incident.start_date <= naive_utcnow(), | ||
) | ||
).all() | ||
|
||
|
@@ -310,7 +312,7 @@ | |
return db.session.scalars( | ||
select(Incident).filter( | ||
Incident.end_date.is_not(None), | ||
Incident.end_date < datetime.datetime.now() | ||
Incident.end_date < naive_utcnow() | ||
) | ||
).all() | ||
|
||
|
@@ -321,7 +323,7 @@ | |
incident_dict = {} | ||
for incident in incident_list: | ||
incident_dict.setdefault( | ||
datetime.datetime( | ||
datetime( | ||
incident.end_date.year, | ||
incident.end_date.month, | ||
1), | ||
|
@@ -338,11 +340,11 @@ | |
return db.session.scalars( | ||
select(Incident).filter( | ||
# already started | ||
Incident.start_date <= datetime.datetime.now(), | ||
Incident.start_date <= naive_utcnow(), | ||
# not closed | ||
or_( | ||
Incident.end_date.is_(None), | ||
Incident.end_date > datetime.datetime.now() | ||
Incident.end_date > naive_utcnow() | ||
), | ||
Incident.impact == 0, | ||
) | ||
|
@@ -353,7 +355,7 @@ | |
"""Return planned maintenances""" | ||
return db.session.scalars( | ||
select(Incident).filter( | ||
Incident.start_date > datetime.datetime.now(), | ||
Incident.start_date > naive_utcnow(), | ||
Incident.impact == 0, | ||
) | ||
).all() | ||
|
@@ -366,7 +368,7 @@ | |
return db.session.scalars( | ||
select(Incident).filter( | ||
# already started | ||
Incident.start_date <= datetime.datetime.now(), | ||
Incident.start_date <= naive_utcnow(), | ||
# not closed | ||
Incident.end_date.is_(None), | ||
Incident.impact != 0, | ||
|
@@ -382,7 +384,7 @@ | |
return db.session.scalars( | ||
select(Incident).filter( | ||
# already started | ||
Incident.start_date <= datetime.datetime.now(), | ||
Incident.start_date <= naive_utcnow(), | ||
# not closed | ||
Incident.end_date.is_(None), | ||
Incident.impact != 0, | ||
|
@@ -442,8 +444,9 @@ | |
id = mapped_column(Integer, primary_key=True, index=True) | ||
incident_id = mapped_column(ForeignKey("incident.id"), index=True) | ||
incident: Mapped["Incident"] = relationship(back_populates="updates") | ||
timestamp: Mapped[datetime.datetime] = mapped_column( | ||
db.DateTime, insert_default=func.now() | ||
timestamp: Mapped[datetime] = mapped_column( | ||
db.DateTime, | ||
insert_default=Text("TIMEZONE('utc', now())") | ||
) | ||
text: Mapped[str] = mapped_column(String()) | ||
status: Mapped[str] = mapped_column(String()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method has no usage anywhere, or it's just for future use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just for future use, can be deleted now