Skip to content

Commit

Permalink
Adds job_metrics file
Browse files Browse the repository at this point in the history
  • Loading branch information
davi-souza committed Aug 29, 2022
1 parent 181488d commit d8ddca8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions target_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from datetime import datetime
import collections
import pkg_resources
import pathlib

from jsonschema.validators import Draft4Validator
import singer
Expand Down Expand Up @@ -96,6 +97,27 @@ def persist_messages(delimiter, quotechar, messages, destination_path, fixed_hea
r = simplejson.dumps(flattened_record)
writer.writerow(simplejson.loads(r))

job_metrics_file_path = os.path.expanduser(os.path.join(destination_path, "job_metrics.json"))

if not os.path.isfile(job_metrics_file_path):
pathlib.Path(job_metrics_file_path).touch()

with open(job_metrics_file_path, 'r+') as job_metrics_file:
content = dict()

try:
content = json.loads(job_metrics_file.read())
except Exception:
pass

if not content.get('recordCount'):
content['recordCount'] = dict()

content['recordCount'][o['stream']] = content['recordCount'].get(o['stream'], 0) + 1

job_metrics_file.seek(0)
job_metrics_file.write(json.dumps(content))

state = None
elif message_type == 'STATE':
logger.debug('Setting state to {}'.format(o['value']))
Expand Down

0 comments on commit d8ddca8

Please sign in to comment.