Skip to content

Commit 69af17e

Browse files
author
Alex Meadows
committed
Merge branches 'master' and 'process_tracker_python-143' of https://github.com/OpenDataAlex/process_tracker_python into process_tracker_python-143
2 parents 2264fc8 + c8650a4 commit 69af17e

File tree

5 files changed

+45
-18
lines changed

5 files changed

+45
-18
lines changed

dbscripts/mysql_process_tracker.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ create table extract_filetype_lkup
7474
(
7575
extract_filetype_id int auto_increment
7676
primary key,
77-
extract_filetype_code varchar(5) not null,
77+
extract_filetype_code varchar(25) not null,
7878
extract_filetype varchar(75) not null,
7979
delimiter_char char null,
8080
quote_char char null,

dbscripts/postgresql_process_tracker.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ create table extract_filetype_lkup
251251
extract_filetype_id serial not null
252252
constraint extract_filetype_lkup_pk
253253
primary key,
254-
extract_filetype_code varchar(5) not null,
254+
extract_filetype_code varchar(25) not null,
255255
extract_filetype varchar(75) not null,
256256
delimiter_char char,
257257
quote_char char,

process_tracker/models/extract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ExtractFileType(Base):
7474
primary_key=True,
7575
nullable=False,
7676
)
77-
extract_filetype_code = Column(String(5), nullable=False)
77+
extract_filetype_code = Column(String(25), nullable=False)
7878
extract_filetype = Column(String(75), nullable=False, unique=True)
7979
delimiter_char = Column(String(1), nullable=True)
8080
quote_char = Column(String(1), nullable=True)

process_tracker/process_tracker.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def __init__(
7979
ProcessTracker is the primary engine for tracking data integration processes.
8080
:param process_name: Name of the process being tracked.
8181
:param process_run_name: Optional name of the process run.
82+
:param process_type: Type of process the process_name is. Optional if process already exists.
8283
:param actor_name: Name of the person or environment runnning the process.
8384
:param tool_name: Name of the tool used to run the process.
8485
:param sources: A single source name or list of source names for the given process. If source_objects is set,
@@ -164,17 +165,15 @@ def __init__(
164165
self.logger.error(error_msg)
165166
raise Exception(error_msg)
166167
else:
167-
if process_name is None or process_type is None:
168-
error_msg = "process_name and process_type must be set."
168+
if process_name is None is None:
169+
error_msg = "process_name must be set."
169170
self.logger.error(error_msg)
170171
raise Exception(error_msg)
171172

172173
self.actor = self.data_store.get_or_create_item(
173174
model=Actor, actor_name=actor_name
174175
)
175-
self.process_type = self.data_store.get_or_create_item(
176-
model=ProcessType, process_type_name=process_type
177-
)
176+
178177
self.tool = self.data_store.get_or_create_item(
179178
model=Tool, tool_name=tool_name
180179
)
@@ -188,13 +187,27 @@ def __init__(
188187
model=ScheduleFrequency, schedule_frequency_name=schedule_frequency
189188
)
190189

191-
self.process = self.data_store.get_or_create_item(
192-
model=Process,
193-
process_name=process_name,
194-
process_type_id=self.process_type.process_type_id,
195-
process_tool_id=self.tool.tool_id,
196-
schedule_frequency_id=self.schedule_frequency.schedule_frequency_id,
197-
)
190+
if process_type is None:
191+
192+
self.process = self.data_store.get_or_create_item(
193+
model=Process, process_name=process_name, create=False
194+
)
195+
196+
self.process_type = self.process.process_type
197+
198+
else:
199+
200+
self.process_type = self.data_store.get_or_create_item(
201+
model=ProcessType, process_type_name=process_type
202+
)
203+
204+
self.process = self.data_store.get_or_create_item(
205+
model=Process,
206+
process_name=process_name,
207+
process_type_id=self.process_type.process_type_id,
208+
process_tool_id=self.tool.tool_id,
209+
schedule_frequency_id=self.schedule_frequency.schedule_frequency_id,
210+
)
198211

199212
# Dataset types should be loaded before source and target because they are also used there.
200213

tests/test_process_tracker.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,7 @@ def test_determine_process_targets(self):
22922292
def test_ensure_nulls_caught_on_instantiation(self):
22932293
"""
22942294
With the adding of the ability of have a process_tracking_id we have to allow for nulled values for process_name
2295-
and process_type. If ProcessTracker is instantiated with either (or both) being null, an exception should be
2295+
. If ProcessTracker is instantiated with process_name being null, an exception should be
22962296
raised.
22972297
:return:
22982298
"""
@@ -2301,6 +2301,20 @@ def test_ensure_nulls_caught_on_instantiation(self):
23012301

23022302
ProcessTracker()
23032303

2304-
return self.assertTrue(
2305-
"process_name and process_type must be set." in str(context.exception)
2304+
return self.assertTrue("process_name must be set." in str(context.exception))
2305+
2306+
def test_ensure_process_type_returned_with_given_process_name(self):
2307+
"""Ensuring that if just the process name is passed, the process type will be retrieved for that given process"""
2308+
2309+
self.process_tracker.change_run_status("completed")
2310+
2311+
test_process = ProcessTracker(
2312+
process_name="Testing Process Tracking Initialization",
2313+
actor_name="UnitTesting",
2314+
tool_name="Spark",
23062315
)
2316+
2317+
given_result = test_process.process_type.process_type_name
2318+
expected_result = "Extract"
2319+
2320+
return self.assertEqual(expected_result, given_result)

0 commit comments

Comments
 (0)