Skip to content

Commit 7479c5e

Browse files
Ilija VukoticBenGalewsky
authored andcommitted
removed code duplication
1 parent f91ce7c commit 7479c5e

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/servicex_did_finder_lib/servicex_adaptor.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,21 @@ def post_status_update(self, status_msg, severity="info"):
7171
def _prefix_file(self, file_path):
7272
return file_path if not self.file_prefix else self.file_prefix+file_path
7373

74+
def _create_json(self, file_info):
75+
return {
76+
"timestamp": datetime.now().isoformat(),
77+
"paths": [self._prefix_file(fp) for fp in file_info['paths']],
78+
'adler32': file_info['adler32'],
79+
'file_size': file_info['file_size'],
80+
'file_events': file_info['file_events']
81+
}
82+
7483
def put_file_add(self, file_info):
7584
success = False
7685
attempts = 0
7786
while not success and attempts < MAX_RETRIES:
7887
try:
79-
mesg = {
80-
"timestamp": datetime.now().isoformat(),
81-
"paths": [self._prefix_file(fp) for fp in file_info['paths']],
82-
'adler32': file_info['adler32'],
83-
'file_size': file_info['file_size'],
84-
'file_events': file_info['file_events']
85-
}
88+
mesg = self._create_json(file_info)
8689
requests.put(self.endpoint + "/files", json=mesg)
8790
self.logger.info(f"Metric: {json.dumps(mesg)}")
8891
success = True
@@ -95,18 +98,12 @@ def put_file_add(self, file_info):
9598
f'message: {str(file_info)} - Ignoring error.')
9699

97100
def put_file_add_bulk(self, file_list):
98-
for chunk in chunks(file_list, 20):
101+
for chunk in chunks(file_list, 30):
99102
success = False
100103
attempts = 0
101104
mesg = []
102105
for fi in chunk:
103-
mesg.append({
104-
"timestamp": datetime.now().isoformat(),
105-
"paths": [self._prefix_file(fp) for fp in fi['paths']],
106-
'adler32': fi['adler32'],
107-
'file_size': fi['file_size'],
108-
'file_events': fi['file_events']
109-
})
106+
mesg.append(self._create_json(fi))
110107
while not success and attempts < MAX_RETRIES:
111108
try:
112109
requests.put(self.endpoint + "/files", json=mesg)

0 commit comments

Comments
 (0)