generated from electron-react-boilerplate/electron-react-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement address reuse check and related refactoring
- Loading branch information
Showing
7 changed files
with
368 additions
and
194 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from sqlalchemy import Enum, Integer | ||
from enum import Enum as PyEnum | ||
|
||
|
||
from src.database import DB | ||
|
||
|
||
class LastFetchedType(PyEnum): | ||
OUTPUTS = "outputs" | ||
|
||
|
||
class LastFetched(DB.Model): | ||
__tablename__ = "last_fetched" | ||
|
||
id = DB.Column(Integer, primary_key=True, autoincrement=True) | ||
type = DB.Column(Enum(LastFetchedType), unique=True, nullable=False) | ||
timestamp = DB.Column(DB.DateTime, nullable=False, default=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
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,40 @@ | ||
from src.models.last_fetched import LastFetched, LastFetchedType | ||
from datetime import datetime | ||
from src.database import DB | ||
from typing import Optional | ||
|
||
import structlog | ||
|
||
LOGGER = structlog.get_logger() | ||
|
||
|
||
class LastFetchedService: | ||
@classmethod | ||
def update_last_fetched_outputs_type( | ||
self, | ||
) -> None: | ||
"""Update the last fetched time for the outputs.""" | ||
timestamp = datetime.now() | ||
current_last_fetched_output = LastFetched.query.filter_by( | ||
type=LastFetchedType.OUTPUTS | ||
).first() | ||
if current_last_fetched_output: | ||
current_last_fetched_output.timestamp = timestamp | ||
else: | ||
last_fetched_output = LastFetched( | ||
type=LastFetchedType.OUTPUTS, timestamp=timestamp | ||
) | ||
DB.session.add(last_fetched_output) | ||
DB.session.commit() | ||
|
||
@classmethod | ||
def get_last_fetched_output_datetime( | ||
self, | ||
) -> Optional[datetime]: | ||
"""Get the last fetched time for the outputs.""" | ||
last_fetched_output = LastFetched.query.filter_by( | ||
type=LastFetchedType.OUTPUTS | ||
).first() | ||
if last_fetched_output: | ||
return last_fetched_output.timestamp | ||
return 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
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
Oops, something went wrong.