Skip to content
This repository was archived by the owner on Mar 13, 2020. It is now read-only.

Commit 3e1a7b2

Browse files
authored
Merge pull request #27 from PageUpPeopleOrg/feature/log-stats-upon-completion
log stats upon completion
2 parents 574c186 + 8335d5f commit 3e1a7b2

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

dpo/Shared.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class StepName:
3636
_defaultLogLevelString = logging.getLevelName(logging.INFO)
3737

3838

39+
def safe_format_number(x, default_value=''):
40+
return default_value if x is None else f'{x:,}'
41+
42+
3943
def configure_root_logger(log_level):
4044
# get the root logger
4145
logger = logging.getLogger()

dpo/commands/CompleteExecutionCommand.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ def __init__(self, db_connection_string, execution_id, logger=None):
99
def execute(self):
1010
execution = self.repository.complete_execution(self._execution_id)
1111
self.logger.debug('Completed Execution: ' + str(execution))
12+
13+
total_execution_seconds = execution.execution_time_ms // 1000
14+
execution_hours = total_execution_seconds // 3600
15+
execution_minutes = (total_execution_seconds // 60) % 60
16+
execution_seconds = total_execution_seconds % 60
17+
self.logger.info(f'Completed Execution ID: {execution.execution_id}; '
18+
f'Started On: {execution.started_on.isoformat()}; '
19+
f'Completed On: {execution.completed_on.isoformat()}; '
20+
f'Execution Time: {execution_hours}h {execution_minutes}m {execution_seconds}s.')
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
from dpo.commands.BaseCommand import BaseCommand
2+
from dpo import Shared
23

34

45
class CompleteStepCommand(BaseCommand):
56
def __init__(self, db_connection_string, step_id, rows_processed, logger=None):
67
super().__init__(db_connection_string, logger)
78
self._step_id = step_id
89
self._rows_processed = rows_processed
10+
self.logger.debug(f'step_id={self._step_id};'
11+
f'rows_processed={self._rows_processed}')
912

1013
def execute(self):
1114
execution_step = self.repository.complete_execution_step(self._step_id, self._rows_processed)
1215
self.logger.debug('Completed Execution Step: ' + str(execution_step))
16+
17+
total_execution_seconds = execution_step.execution_time_ms // 1000
18+
execution_hours = total_execution_seconds // 3600
19+
execution_minutes = (total_execution_seconds // 60) % 60
20+
execution_seconds = total_execution_seconds % 60
21+
execution_step_models = self.repository.get_execution_step_models(self._step_id)
22+
self.logger.info(f'Completed Execution Step: {execution_step.step_name}; '
23+
f'Started On: {execution_step.started_on.isoformat()}; '
24+
f'Completed On: {execution_step.completed_on.isoformat()}; '
25+
f'Execution Time: {execution_hours}h {execution_minutes}m {execution_seconds}s; '
26+
f'Models Processed: {Shared.safe_format_number(len(execution_step_models))}; '
27+
f'Rows Processed: {Shared.safe_format_number(execution_step.rows_processed, "N/A")}.')

dpo/entities/execution_entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ def __str__(self):
5454
f'status={self.status}, ' \
5555
f'started_on={self.started_on}, ' \
5656
f'completed_on={self.completed_on}, ' \
57-
f'execution_time_ms={self.execution_time_ms}.'
57+
f'execution_time_ms={Shared.safe_format_number(self.execution_time_ms)}.'

dpo/entities/execution_step_entity.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ class ExecutionStepEntity(Shared.BaseEntity):
6565
nullable=True)
6666

6767
def __str__(self):
68-
return f'execution_step_id={self.execution_step_id}, ' \
68+
return f'execution_id={self.execution_id}, ' \
69+
f'execution_step_id={self.execution_step_id}, ' \
6970
f'created_on={self.created_on}, ' \
7071
f'updated_on={self.updated_on}, ' \
71-
f'execution_id={self.execution_id}, ' \
7272
f'step_name={self.step_name}, ' \
7373
f'status={self.status}, ' \
7474
f'started_on={self.started_on}, ' \
7575
f'completed_on={self.completed_on}, ' \
76-
f'execution_time_ms={self.execution_time_ms}, ' \
77-
f'rows_processed={self.rows_processed}.'
76+
f'execution_time_ms={Shared.safe_format_number(self.execution_time_ms)}, ' \
77+
f'rows_processed={Shared.safe_format_number(self.rows_processed)}.'

0 commit comments

Comments
 (0)