[Migration] remove unused mgmt cmd listening-stats
[mygpo.git] / mygpo / maintenance / models.py
blob2658414800c07ee7ab7b4bc25db70da0a6686d46
1 from couchdbkit.ext.django.schema import *
4 class CommandRunStatus(DocumentSchema):
5 """ Status of a single Command run """
7 timestamp_started = DateTimeProperty()
8 timestamp_finished = DateTimeProperty()
9 error_msg = StringProperty()
10 start_seq = IntegerProperty()
11 end_seq = IntegerProperty()
12 status_counter = DictProperty()
14 def __repr__(self):
15 return '<%(cls)s %(start_seq)d - %(end_seq)d>' % \
16 dict(cls=self.__class__.__name__, start_seq=self.start_seq,
17 end_seq=self.end_seq)
20 class CommandStatus(Document):
21 """ Contains status info for several runs of a command """
23 command = StringProperty()
24 runs = SchemaListProperty(CommandRunStatus)
27 @property
28 def last_seq(self):
29 runs = filter(lambda r: r.end_seq, self.runs)
30 return runs[-1].end_seq if runs else 0
33 def __repr__(self):
34 return '<%(cls)s %(cmd)s %(num_runs)d>' % \
35 dict(cls=self.__class__.__name__, cmd=self.command,
36 num_runs=len(self.runs))