forked from ancorisrm/ancoris
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.py
More file actions
executable file
·50 lines (38 loc) · 1.37 KB
/
worker.py
File metadata and controls
executable file
·50 lines (38 loc) · 1.37 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from catenae import Link, Electron, rpc, utils as catenae_utils
from errors import UnsupportedDevice, ContainerError
from docker_manager import Docker
from common import startup_text
from threading import Thread
class AncorisWorker(Link):
def setup(self):
self.docker = Docker(self)
@rpc
def run(self, **kwargs):
# El worker decide si acepta el trabajo o no
# Si lo acepta devuelve el id del contenedor
# Check resources
if not AncorisWorker.accept_container(kwargs):
raise NotImplementedError
container_auid = catenae_utils.get_uid()
AncorisWorker.adapt_request(container_auid, kwargs)
self.launch_thread(self.docker.run, kwargs=kwargs)
return {'container_auid': container_auid}
@rpc
def remove(self, context, container_auid):
print(container_auid)
# if I have the container
self.docker.remove(container_auid)
# try:
# self.launch_thread(self.docker.remove, container_auid)
# except Exception:
# pass
@staticmethod
def adapt_request(container_auid, request):
request['name'] = f'ancoris_{container_auid}'
@staticmethod
def accept_container(kwargs):
return True
if __name__ == "__main__":
AncorisWorker().start(startup_text=startup_text)