-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
97 changed files
with
2,283 additions
and
887 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
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ tmuxp | |
livereload | ||
ipython | ||
slash | ||
yarl |
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
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,41 @@ | ||
import flux | ||
from ...models import Timing, db | ||
from ...utils.db_utils import json_object_agg | ||
from .blueprint import API | ||
|
||
from sqlalchemy import case | ||
|
||
NoneType = type(None) | ||
|
||
|
||
@API | ||
def report_timing_start(name: str, session_id: int, test_id: (int, NoneType)=None): # pylint: disable=bad-whitespace | ||
db.session.execute( | ||
''' | ||
INSERT INTO timing(session_id, test_id, name, total) | ||
VALUES (:session_id, :test_id, :name, :interval) | ||
ON CONFLICT(id) DO UPDATE SET total = timing.total + EXCLUDED.total''', | ||
{'session_id': session_id, 'test_id': test_id, 'name': name, 'interval': -flux.current_timeline.time()}) | ||
db.session.commit() | ||
|
||
|
||
@API | ||
def report_timing_end(name: str, session_id: int, test_id: (int, NoneType)=None): # pylint: disable=bad-whitespace | ||
timing = Timing.query.filter_by(session_id=session_id, test_id=test_id, name=name).first_or_404() | ||
timing.total = Timing.total + flux.current_timeline.time() | ||
db.session.commit() | ||
|
||
|
||
@API | ||
def get_timings(session_id: (int, NoneType)=None, test_id: (int, NoneType)=None): | ||
now = flux.current_timeline.time() | ||
total_clause = case( | ||
[ | ||
(Timing.total < 0, now - Timing.total) | ||
], else_=Timing.total) | ||
kwargs = {'test_id': test_id} | ||
if session_id is not None: | ||
kwargs['session_id'] = session_id | ||
query = db.session.query(json_object_agg(Timing.name, total_clause)).\ | ||
filter_by(**kwargs) | ||
return query.scalar() or {} |
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,37 @@ | ||
# pylint: disable=bad-whitespace | ||
from flask import current_app | ||
from flask_simple_api import error_abort | ||
from .blueprint import API | ||
from ...models import Session, Warning, Test, db | ||
from ...utils import get_current_time | ||
|
||
|
||
@API | ||
def add_warning(message:str, filename:str=None, lineno:int=None, test_id:int=None, session_id:int=None, timestamp:(int,float)=None): | ||
# pylint: disable=superfluous-parens | ||
if not ((test_id is not None) ^ (session_id is not None)): | ||
error_abort('Either session_id or test_id required') | ||
|
||
if session_id is not None: | ||
obj = Session.query.get_or_404(session_id) | ||
else: | ||
obj = Test.query.get_or_404(test_id) | ||
|
||
if timestamp is None: | ||
timestamp = get_current_time() | ||
|
||
warning = Warning.query.filter_by(session_id=session_id, test_id=test_id, lineno=lineno, filename=filename, message=message).first() | ||
if warning is None: | ||
if obj.num_warnings < current_app.config['MAX_WARNINGS_PER_ENTITY']: | ||
warning = Warning(message=message, timestamp=timestamp, filename=filename, lineno=lineno, test_id=test_id, session_id=session_id) | ||
db.session.add(warning) | ||
else: | ||
warning.num_warnings = Warning.num_warnings + 1 | ||
warning.timestamp = timestamp | ||
|
||
obj.num_warnings = type(obj).num_warnings + 1 | ||
if session_id is None: | ||
obj.session.num_test_warnings = Session.num_test_warnings + 1 | ||
db.session.add(obj.session) | ||
|
||
db.session.commit() |
Oops, something went wrong.