-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #428 from alexhsamuel/feature/vacuum-program
vacuum program
- Loading branch information
Showing
7 changed files
with
117 additions
and
14 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
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,57 @@ | ||
import logging | ||
|
||
from ..base import _InternalProgram, ProgramRunning, ProgramSuccess | ||
from apsis.lib.json import check_schema | ||
from apsis.lib.timing import Timer | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
#------------------------------------------------------------------------------- | ||
|
||
class VacuumProgram(_InternalProgram): | ||
""" | ||
A program that defragments the Apsis database. | ||
This program runs within the Apsis process, and blocks all other activities | ||
while it runs. | ||
""" | ||
|
||
def __str__(self): | ||
return "vacuum database" | ||
|
||
|
||
def bind(self, args): | ||
return self | ||
|
||
|
||
def to_jso(self): | ||
return { | ||
**super().to_jso() | ||
} | ||
|
||
|
||
@classmethod | ||
def from_jso(cls, jso): | ||
with check_schema(jso) as pop: | ||
pass | ||
return cls() | ||
|
||
|
||
async def start(self, run_id, apsis): | ||
return ProgramRunning({}), self.wait(apsis) | ||
|
||
|
||
async def wait(self, apsis): | ||
# FIXME: Private attributes. | ||
db = apsis._Apsis__db | ||
|
||
with Timer() as timer: | ||
db.vacuum() | ||
|
||
meta = { | ||
"time": timer.elapsed, | ||
} | ||
return ProgramSuccess(meta=meta) | ||
|
||
|
||
|
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 @@ | ||
*.db |
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,7 @@ | ||
params: [label, age] | ||
|
||
program: | ||
type: apsis.program.internal.archive.ArchiveProgram | ||
age: "{{ age }}" | ||
path: "/home/alex/dev/apsis/test/manual/procstar/archive/{{ label }}.db" | ||
count: 1000000 |
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,3 @@ | ||
program: | ||
type: apsis.program.internal.vacuum.VacuumProgram | ||
|