-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathbatches.py
More file actions
57 lines (44 loc) · 1.46 KB
/
batches.py
File metadata and controls
57 lines (44 loc) · 1.46 KB
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
from enum import Enum
class BatchStatus(Enum):
"""Status of Batches"""
Staging = "staging"
InProgress = "in_progress"
Completed = "completed"
class Batch:
"""Batch class, contains Batch information"""
def __init__(self, json, client):
self._json = json
self.name = json["name"]
self.status = json["status"]
self.project = json["project"]
self.created_at = json["created_at"]
self.project = json["project"]
self.metadata = json["metadata"]
self.tasks_pending = None
self.tasks_completed = None
self.tasks_error = None
self.tasks_canceled = None
self._client = client
def __hash__(self):
return hash(self.name)
def __str__(self):
return f"Batch(name={self.name})"
def __repr__(self):
return f"Batch({self._json})"
def as_dict(self):
"""Returns all attributes as a dictionary"""
return self._json
def finalize(self):
"""Finalizes the batch"""
res = self._client.finalize_batch(self.name)
self.status = res.status
return res
def get_status(self):
"""Returns status of the batch and
updates tasks_... parameters
"""
res = self._client.batch_status(self.name)
self.status = res["status"]
for stat in ["pending", "completed", "error", "canceled"]:
setattr(self, "tasks_" + stat, res.get(stat, 0))
return res