Skip to content

Commit

Permalink
some adjustments to flatfile observer
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwlouse committed Jun 9, 2016
1 parent 2f96b74 commit 7e01671
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions sacred/observers/flatfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,21 @@ def started_event(self, ex_info, command, host_info, start_time, config,
'command': command,
'host': dict(host_info),
'start_time': start_time,
'config': config,
'meta': meta_info,
'status': 'RUNNING',
'resources': [],
'artifacts': [],
'info': {},
'heartbeat': None
}
self.save()
self.save_json(self.run_entry, 'run.json')
self.save_json(config, 'config.json')
self.save_cout('')

for s, m in ex_info['sources']:
self.save_file(s)

return os.path.relpath(self.dir, self.basedir) if _id is None else _id

def save(self):
with open(os.path.join(self.dir, 'run.json'), 'w') as f:
json.dump(self.run_entry, f, indent=2, sort_keys=True,
default=json_serial)

def save_file(self, filename):
from shutil import copyfile
fn = os.path.basename(filename)
Expand All @@ -72,39 +66,44 @@ def save_cout(self, cout):
with open(os.path.join(self.dir, 'cout.txt'), 'w') as f:
f.write(cout)

def save_json(self, obj, filename):
with open(os.path.join(self.dir, filename), 'w') as f:
json.dump(obj, f, indent=2, sort_keys=True,
default=json_serial)

def heartbeat_event(self, info, captured_out, beat_time):
self.run_entry['info'] = info
self.save_cout(captured_out)
self.run_entry['heartbeat'] = beat_time
self.save()
self.save_json(self.run_entry, 'run.json')
self.save_json(info, 'info.json')

def completed_event(self, stop_time, result):
self.run_entry['stop_time'] = stop_time
self.run_entry['result'] = result
self.run_entry['status'] = 'COMPLETED'
self.save()
self.save_json(self.run_entry, 'run.json')

def interrupted_event(self, interrupt_time, status):
self.run_entry['stop_time'] = interrupt_time
self.run_entry['status'] = status
self.save()
self.save_json(self.run_entry, 'run.json')

def failed_event(self, fail_time, fail_trace):
self.run_entry['stop_time'] = fail_time
self.run_entry['status'] = 'FAILED'
self.run_entry['fail_trace'] = fail_trace
self.save()
self.save_json(self.run_entry, 'run.json')

def resource_event(self, filename):
self.save_file(filename)
md5hash = get_digest(filename)
self.run_entry['resources'].append((filename, md5hash))
self.save()
self.save_json(self.run_entry, 'run.json')

def artifact_event(self, filename):
self.save_file(filename)
self.run_entry['artifacts'].append(filename)
self.save()
self.save_json(self.run_entry, 'run.json')


class FlatfileOption(CommandLineOption):
Expand Down

0 comments on commit 7e01671

Please sign in to comment.