-
Notifications
You must be signed in to change notification settings - Fork 6
/
models.py
60 lines (43 loc) · 1.41 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import peewee
db = peewee.SqliteDatabase('db.sqlite')
class Repo(peewee.Model):
name = peewee.CharField() # TODO make this uniq/index
url = peewee.CharField()
revision = peewee.CharField(null=True)
state = peewee.CharField(choices=(
('working', 'Working'),
('other_than_working', 'Other than working'),
), default="other_than_working")
random_job_day = peewee.IntegerField(null=True)
class Meta:
database = db
class Job(peewee.Model):
name = peewee.CharField()
url_or_path = peewee.CharField()
state = peewee.CharField(choices=(
('scheduled', 'Scheduled'),
('runnning', 'Running'),
('done', 'Done'),
('failure', 'Failure'),
('error', 'Error'),
('canceled', 'Canceled'),
), default="scheduled")
log = peewee.TextField(default="")
created_time = peewee.DateTimeField(constraints=[peewee.SQL("DEFAULT (datetime('now'))")])
started_time = peewee.DateTimeField(null=True)
end_time = peewee.DateTimeField(null=True)
class Meta:
database = db
class Worker(peewee.Model):
state = peewee.CharField(choices=(
('available', 'Available'),
('busy', 'Busy'),
))
class Meta:
database = db
# peewee is a bit stupid and will crash if the table already exists
for i in [Repo, Job, Worker]:
try:
i.create_table()
except Exception:
pass