Skip to content

Commit

Permalink
Merge 77e02f6 into 99f378c
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenDataAlex committed Nov 22, 2019
2 parents 99f378c + 77e02f6 commit dddc460
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 23 deletions.
2 changes: 2 additions & 0 deletions dbscripts/mysql_process_tracker.sql
Expand Up @@ -263,6 +263,8 @@ create table process
process_tool_id int null,
last_failed_run_date_time datetime not null,
schedule_frequency_id int default 0 not null,
last_completed_run_date_time datetime not null,
last_errored_run_date_time datetime not null,
constraint process_name
unique (process_name),
constraint process_fk03
Expand Down
5 changes: 3 additions & 2 deletions dbscripts/postgresql_process_tracker.sql
Expand Up @@ -3,7 +3,6 @@ SET search_path TO process_tracker;
create schema process_tracker;

alter schema process_tracker owner to pt_admin;

create schema process_tracker;

alter schema process_tracker owner to pt_admin;
Expand Down Expand Up @@ -303,7 +302,9 @@ create table process
last_failed_run_date_time timestamp default '1900-01-01 00:00:00'::timestamp without time zone not null,
schedule_frequency_id integer default 0 not null
constraint process_fk04
references schedule_frequency_lkup
references schedule_frequency_lkup,
last_completed_run_date_time timestamp default '1900-01-01 00:00:00'::timestamp without time zone not null,
last_errored_run_date_time timestamp default '1900-01-01 00:00:00'::timestamp without time zone not null
);

comment on table process is 'Processes being tracked';
Expand Down
6 changes: 6 additions & 0 deletions process_tracker/models/process.py
Expand Up @@ -148,6 +148,12 @@ class Process(Base):
last_failed_run_date_time = Column(
DateTime(timezone=True), nullable=False, default=default_date
)
last_completed_run_date_time = Column(
DateTime(timezone=True), nullable=False, default=default_date
)
last_errored_run_date_time = Column(
DateTime(timezone=True), nullable=False, default=default_date
)
schedule_frequency_id = Column(
Integer,
ForeignKey("process_tracker.schedule_frequency_lkup.schedule_frequency_id"),
Expand Down
21 changes: 10 additions & 11 deletions process_tracker/process_tracker.py
Expand Up @@ -267,20 +267,19 @@ def change_run_status(self, new_status, end_date=None):
new_status
]

if (
self.process_status_types[new_status] == self.process_status_complete
) or (self.process_status_types[new_status] == self.process_status_failed):

self.logger.info("Process status changing to failed or completed.")

if self.process_status_types[new_status] == self.process_status_complete:
self.logger.info("Process status changing to completed.")
self.process.last_completed_run_date_time = end_date
self.process_tracking_run.process_run_end_date_time = end_date

if self.process_status_types[new_status] == self.process_status_failed:
self.logger.info(
"Process recording as failed. Setting process last_failed_run_date_time."
)
elif self.process_status_types[new_status] == self.process_status_failed:

self.logger.info(
"Process recording as failed. Setting process last_failed_run_date_time."
)

self.process.last_failed_run_date_time = end_date
self.process.last_failed_run_date_time = end_date
self.process_tracking_run.process_run_end_date_time = end_date

self.session.commit()

Expand Down
42 changes: 32 additions & 10 deletions tests/test_process_tracker.py
Expand Up @@ -1559,32 +1559,54 @@ def test_register_process_target_object_attributes(self):
def test_change_run_status_complete(self):
"""
Testing that when changing the run status from 'running' to 'complete' the run record updates successfully.
Process record is also updated for last_completed_date_time.
:return:
"""
self.process_tracker.change_run_status(new_status="completed")
end_date = datetime.now()
end_date = end_date.replace(microsecond=0)
self.process_tracker.change_run_status(
new_status="completed", end_date=end_date
)

run_record = self.session.query(ProcessTracking).filter(
ProcessTracking.process_id == self.process_id
run_record = (
self.session.query(
ProcessTracking.process_status_id, Process.last_completed_run_date_time
)
.join(Process)
.filter(ProcessTracking.process_id == self.process_id)
)

given_result = run_record[0].process_status_id
expected_result = self.process_tracker.process_status_complete
given_result = [
run_record[0].process_status_id,
run_record[0].last_completed_run_date_time,
]
expected_result = [self.process_tracker.process_status_complete, end_date]

self.assertEqual(expected_result, given_result)

def test_change_run_status_failed(self):
"""
Testing that when changing the run status from 'running' to 'failed' the run record updates successfully.
Process record is also updated for last_failed_date_time.
:return:
"""
self.process_tracker.change_run_status(new_status="failed")
end_date = datetime.now()
end_date = end_date.replace(microsecond=0)
self.process_tracker.change_run_status(new_status="failed", end_date=end_date)

run_record = self.session.query(ProcessTracking).filter(
ProcessTracking.process_id == self.process_id
run_record = (
self.session.query(
ProcessTracking.process_status_id, Process.last_failed_run_date_time
)
.join(Process)
.filter(ProcessTracking.process_id == self.process_id)
)

given_result = run_record[0].process_status_id
expected_result = self.process_tracker.process_status_failed
given_result = [
run_record[0].process_status_id,
run_record[0].last_failed_run_date_time,
]
expected_result = [self.process_tracker.process_status_failed, end_date]

self.assertEqual(expected_result, given_result)

Expand Down

0 comments on commit dddc460

Please sign in to comment.