-
Notifications
You must be signed in to change notification settings - Fork 4
/
models.py
131 lines (94 loc) · 3.79 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from tortoise.models import Model
from tortoise import fields
# Models for interacting with the SQL database.
# Job -> pending=True -> pending=False, closed=True
# Job -> pending=True -> gpu=True, pending=False -> (same as above from pending=True)
class Job(Model):
""" The SQL Hybrid open jobs table. """
# The shard number.
number = fields.IntField(pk=True)
# The URL to download the shard from CommonCrawl.
url = fields.CharField(max_length=500)
# The starting and ending sample IDs for this entire chunk (= 2 shards)
start_id = fields.CharField(max_length=255)
end_id = fields.CharField(max_length=255)
# The shard of the chunk: 0 = first 50%, 1 = last 50%.
shard_of_chunk = fields.IntField()
# GPU job information (not always used)
gpu = fields.BooleanField()
gpu_url = fields.CharField(max_length=500, null=True)
# Contains information about the shard's completion.
pending = fields.BooleanField()
closed = fields.BooleanField()
# User data
completor = fields.CharField(max_length=255, null=True) # Initially contains the worker's token whilst being processed, but contains the user's nickname on completion.
cpu_completor = fields.CharField(max_length=255, null=True) # (contains the CPU worker's user nickname on completion if this shard was also processed using a CPU worker)
# The shard in string format (for debugging)
def __str__(self):
if self.completed:
c = "Completed"
elif self.pending:
c = "Pending"
else:
c = "Open"
return c + " job with shard number #" + str(self.number)
class Client(Model):
""" The SQL Clients table. """
# The UUID of the client.
uuid = fields.CharField(max_length=255, pk=True)
display_name = fields.CharField(max_length=255)
# The type of client. (HYBRID/CPU/GPU)
type = fields.CharField(max_length=6)
# User information.
user_nickname = fields.CharField(max_length=255)
# The shard this client is currently processing.
shard = fields.ForeignKeyField("models.Job", related_name="worker", null=True)
# Progress information sent from the client. ( client.log(...) )
progress = fields.CharField(max_length=255)
# How many jobs this client has completed
jobs_completed = fields.IntField()
# Client time information in a UTC epoch timestamp form. (helps with timeouts as well as calculating efficiency)
first_seen = fields.IntField()
last_seen = fields.IntField()
def __str__(self):
return self.type + " Client with UUID " + self.uuid
class Leaderboard(Model):
""" The Hybrid/GPU job completion leaderboard. """
# The user's nickname
nickname = fields.CharField(max_length=255, pk=True)
# Data about the user.
jobs_completed = fields.IntField(default=0)
pairs_scraped = fields.IntField(default=0)
class CPU_Leaderboard(Model):
""" The CPU job completion leaderboard. """
# The user's nickname
nickname = fields.CharField(max_length=255, pk=True)
# Data about the user.
jobs_completed = fields.IntField(default=0)
# CUSTOM SQL QUERIES:
CUSTOM_QUERY_GPU = """
UPDATE "job"
SET pending=true, completor='{}'
WHERE "number" IN
(
SELECT "number" FROM "job"
WHERE pending=false AND closed=false AND gpu=true
ORDER BY RANDOM() LIMIT 1
FOR UPDATE SKIP LOCKED
)
AND pending=false AND closed=false AND gpu=true
;
"""
CUSTOM_QUERY_CPU_HYBRID = """
UPDATE "job"
SET pending=true, completor='{}'
WHERE "number" IN
(
SELECT "number" FROM "job"
WHERE pending=false AND closed=false AND gpu=false
ORDER BY RANDOM() LIMIT 1
FOR UPDATE SKIP LOCKED
)
AND pending=false AND closed=false AND gpu=false
;
"""