Skip to content

Commit e0017a9

Browse files
author
Alex Meadows
committed
process_tracker_python-137 Add Instance name to Process Tracker table
✨ Process instances can now have optional unique names Closes #137
1 parent c458619 commit e0017a9

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

dbscripts/mysql_process_tracker.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ create table process_tracking
337337
process_run_record_count int not null,
338338
process_run_actor_id int null,
339339
is_latest_run tinyint(1) not null,
340+
process_run_name varchar(250) null,
341+
constraint process_tracking_process_run_name_uindex
342+
unique (process_run_name),
340343
constraint process_tracking_ibfk_1
341344
foreign key (process_id) references process (process_id),
342345
constraint process_tracking_ibfk_2
@@ -345,6 +348,8 @@ create table process_tracking
345348
foreign key (process_run_actor_id) references actor_lkup (actor_id)
346349
);
347350

351+
352+
348353
create table error_tracking
349354
(
350355
error_tracking_id int auto_increment

dbscripts/postgresql_process_tracker.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ create table process_tracking
364364
process_run_actor_id integer
365365
constraint process_tracking_fk03
366366
references actor_lkup,
367-
is_latest_run boolean default false
367+
is_latest_run boolean default false,
368+
process_run_name varchar(250) null
368369
);
369370

370371
comment on table process_tracking is 'Tracking table of process runs.';
@@ -400,6 +401,9 @@ create index process_tracking_idx02
400401
create index process_tracking_idx03
401402
on process_tracking (process_run_low_date_time, process_run_high_date_time);
402403

404+
create unique index process_tracking_udx01
405+
on process_tracking (process_run_name);
406+
403407
create table cluster_process
404408
(
405409
cluster_id integer not null

process_tracker/models/process.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ class ProcessTracking(Base):
512512
Integer, ForeignKey("process_tracker.actor_lkup.actor_id"), nullable=False
513513
)
514514
is_latest_run = Column(Boolean, nullable=False, default=False)
515+
process_run_name = Column(String(250), unique=True, nullable=True)
515516

516517
actor = relationship("Actor")
517518
errors = relationship(

process_tracker/process_tracker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class ProcessTracker:
6060
def __init__(
6161
self,
6262
process_name=None,
63+
process_run_name=None,
6364
process_type=None,
6465
actor_name=None,
6566
tool_name=None,
@@ -77,6 +78,7 @@ def __init__(
7778
"""
7879
ProcessTracker is the primary engine for tracking data integration processes.
7980
:param process_name: Name of the process being tracked.
81+
:param process_run_name: Optional name of the process run.
8082
:param actor_name: Name of the person or environment runnning the process.
8183
:param tool_name: Name of the tool used to run the process.
8284
:param sources: A single source name or list of source names for the given process. If source_objects is set,
@@ -148,6 +150,7 @@ def __init__(
148150

149151
self.process_name = process_run.process.process_name
150152
self.process_tracking_run = process_run
153+
self.process_run_name = process_run.process_run_name
151154

152155
else:
153156
error_msg = "Process run not found based on id %s." % process_run_id
@@ -231,6 +234,7 @@ def __init__(
231234
self.targets = None
232235

233236
self.process_name = process_name
237+
self.process_run_name = process_run_name
234238

235239
self.process_tracking_run = self.register_new_process_run()
236240

@@ -976,6 +980,7 @@ def register_new_process_run(self):
976980
process_run_start_date_time=datetime.now(),
977981
process_run_actor_id=self.actor.actor_id,
978982
is_latest_run=True,
983+
process_run_name=self.process_run_name,
979984
)
980985

981986
self.session.add(new_run)

tests/test_process_tracker.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def setUp(self):
9999
"""
100100
self.process_tracker = ProcessTracker(
101101
process_name="Testing Process Tracking Initialization",
102+
process_run_name="Testing Process Tracking Initialization 01",
102103
process_type="Extract",
103104
actor_name="UnitTesting",
104105
tool_name="Spark",
@@ -1054,6 +1055,9 @@ def test_register_new_process_run_with_previous_run(self):
10541055
"""
10551056

10561057
self.process_tracker.change_run_status(new_status="completed")
1058+
self.process_tracker.process_run_name = (
1059+
"Testing Process Tracking Initialization 02"
1060+
)
10571061
self.process_tracker.register_new_process_run()
10581062

10591063
process_runs = (
@@ -1087,6 +1091,9 @@ def test_register_new_process_run_dependencies_completed(self):
10871091
child_process_id=self.process_id,
10881092
)
10891093

1094+
self.process_tracker.process_run_name = (
1095+
"Testing Process Tracking Initialization 02"
1096+
)
10901097
self.process_tracker.register_new_process_run()
10911098

10921099
given_count = (
@@ -2166,13 +2173,17 @@ def test_process_tracker_with_process_run_id(self):
21662173
new_process_tracker.schedule_frequency.schedule_frequency_name
21672174
)
21682175

2176+
expected_process_run_name = self.process_tracker.process_run_name
2177+
given_process_run_name = new_process_tracker.process_run_name
2178+
21692179
self.assertEqual(expected_process_name_result, given_process_name_result)
21702180
self.assertEqual(expected_actor_result, given_actor_result)
21712181
self.assertEqual(expected_process_type_result, given_process_type_result)
21722182
self.assertEqual(expected_tool_result, given_tool_result)
21732183
self.assertEqual(
21742184
expected_schedule_frequency_result, given_schedule_frequency_result
21752185
)
2186+
self.assertEqual(expected_process_run_name, given_process_run_name)
21762187

21772188
def test_determine_process_sources(self):
21782189
"""

0 commit comments

Comments
 (0)