-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added new SQLiteCheckpointer. - Exposed internal execution loop trigger intervals in the config section of the JobDefinition. - `synchro_interval_seconds` - `loggers_interval_seconds` - `extensions_interval_seconds` - `checkpointer_interval_seconds` - Added basic Checkpoint validation to check checkpoint contents against the given JobDefinition. - Renamed the `checkpointer_config` section to simply `checkpointer`.
- Loading branch information
Showing
19 changed files
with
309 additions
and
150 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[bumpversion] | ||
current_version = 0.7.2 | ||
current_version = 0.8.0 | ||
files = flowmancer/version.py pyproject.toml |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# noqa: F401 | ||
# Ensure implementations are registered | ||
from . import file | ||
from . import database, file | ||
from .checkpointer import CheckpointContents, Checkpointer, NoCheckpointAvailableError, checkpointer | ||
|
||
__all__ = ['Checkpointer', 'CheckpointContents', 'NoCheckpointAvailableError', 'checkpointer'] |
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,75 @@ | ||
import pickle | ||
import sqlite3 | ||
from contextlib import closing | ||
from typing import Optional | ||
from uuid import UUID, uuid4 | ||
|
||
from .checkpointer import CheckpointContents, Checkpointer, NoCheckpointAvailableError, checkpointer | ||
|
||
|
||
@checkpointer | ||
class SQLiteCheckpointer(Checkpointer): | ||
class SQLiteCheckpointerState: | ||
def __init__(self): | ||
self.con: Optional[sqlite3.Connection] = None | ||
self.uuid: UUID = uuid4() | ||
|
||
_state: SQLiteCheckpointerState = SQLiteCheckpointerState() | ||
checkpoint_database: str = './.flowmancer/checkpoint.db' | ||
|
||
@property | ||
def _con(self) -> sqlite3.Connection: | ||
if not self._state.con: | ||
self._state.con = sqlite3.connect(self.checkpoint_database) | ||
self._state.con.row_factory = sqlite3.Row | ||
return self._state.con | ||
|
||
async def on_create(self) -> None: | ||
self._con.execute(''' | ||
CREATE TABLE IF NOT EXISTS checkpoint ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
uuid TEXT NOT NULL UNIQUE, | ||
name TEXT NOT NULL, | ||
start_ts DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
end_ts DATETIME, | ||
checkpoint_contents BLOB | ||
) | ||
''') | ||
|
||
async def on_destroy(self) -> None: | ||
if self._state.con: | ||
self._state.con.close() | ||
|
||
async def write_checkpoint(self, name: str, content: CheckpointContents) -> None: | ||
dumped_content = sqlite3.Binary(pickle.dumps(content)) | ||
params = [str(self._state.uuid), name, dumped_content, dumped_content] | ||
self._con.execute(''' | ||
INSERT INTO checkpoint (uuid, name, checkpoint_contents) VALUES (?, ?, ?) | ||
ON CONFLICT(uuid) DO UPDATE SET checkpoint_contents = ? | ||
''', params) | ||
self._con.commit() | ||
|
||
async def read_checkpoint(self, name: str) -> CheckpointContents: | ||
with closing(self._con.cursor()) as cur: | ||
# Check if the checkpoint table exists. In the event of first ever execution for the given DB, no such | ||
# table will exist and therefore no checkpoints exist. | ||
cur.execute("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'checkpoint'") | ||
row = cur.fetchone() | ||
if not row: | ||
raise NoCheckpointAvailableError(f'Checkpoint entry does not exist for: {name}') | ||
|
||
cur.execute('SELECT * FROM checkpoint WHERE name = ? ORDER BY id DESC LIMIT 1', [name]) | ||
row = cur.fetchone() | ||
if row and not row['end_ts']: | ||
self._state.uuid = UUID(row['uuid']) | ||
else: | ||
raise NoCheckpointAvailableError(f'Checkpoint entry does not exist for: {name}') | ||
|
||
return pickle.loads(row['checkpoint_contents']) | ||
|
||
async def clear_checkpoint(self, _: str) -> None: | ||
self._con.execute( | ||
'UPDATE checkpoint SET end_ts = CURRENT_TIMESTAMP WHERE uuid = ?', | ||
[str(self._state.uuid)] | ||
) | ||
self._con.commit() |
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,14 @@ | ||
class NoTasksLoadedError(Exception): | ||
pass | ||
|
||
|
||
class ExtensionsDirectoryNotFoundError(Exception): | ||
pass | ||
|
||
|
||
class NotAPackageError(Exception): | ||
pass | ||
|
||
|
||
class CheckpointInvalidError(Exception): | ||
pass |
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
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.