-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmodels.py
70 lines (53 loc) · 1.53 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
61
62
63
64
65
66
67
68
69
70
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