Code Duplication    Length = 21-21 lines in 2 locations

sacred/observers/sql.py 2 locations

@@ 58-78 (lines=21) @@
55
        self.save()
56
        return _id or self.run.run_id
57
58
    def queued_event(self, ex_info, command, host_info, queue_time, config,
59
                     meta_info, _id):
60
61
        Base.metadata.create_all(self.engine)
62
        sql_exp = Experiment.get_or_create(ex_info, self.session)
63
        sql_host = Host.get_or_create(host_info, self.session)
64
        if _id is None:
65
            i = self.session.query(Run).order_by(Run.id.desc()).first()
66
            _id = 0 if i is None else i.id + 1
67
68
        self.run = Run(run_id=str(_id),
69
                       config=json.dumps(flatten(config)),
70
                       command=command,
71
                       priority=meta_info.get('priority', 0),
72
                       comment=meta_info.get('comment', ''),
73
                       experiment=sql_exp,
74
                       host=sql_host,
75
                       status='QUEUED')
76
        self.session.add(self.run)
77
        self.save()
78
        return _id or self.run.run_id
79
80
    def heartbeat_event(self, info, captured_out, beat_time, result):
81
        self.run.info = json.dumps(flatten(info))
@@ 36-56 (lines=21) @@
33
        self.run = None
34
        self.lock = Lock()
35
36
    def started_event(self, ex_info, command, host_info, start_time, config,
37
                      meta_info, _id):
38
        Base.metadata.create_all(self.engine)
39
        sql_exp = Experiment.get_or_create(ex_info, self.session)
40
        sql_host = Host.get_or_create(host_info, self.session)
41
        if _id is None:
42
            i = self.session.query(Run).order_by(Run.id.desc()).first()
43
            _id = 0 if i is None else i.id + 1
44
45
        self.run = Run(run_id=str(_id),
46
                       start_time=start_time,
47
                       config=json.dumps(flatten(config)),
48
                       command=command,
49
                       priority=meta_info.get('priority', 0),
50
                       comment=meta_info.get('comment', ''),
51
                       experiment=sql_exp,
52
                       host=sql_host,
53
                       status='RUNNING')
54
        self.session.add(self.run)
55
        self.save()
56
        return _id or self.run.run_id
57
58
    def queued_event(self, ex_info, command, host_info, queue_time, config,
59
                     meta_info, _id):