mirror of
https://github.com/simon987/task_tracker_drone.git
synced 2025-04-20 02:36:43 +00:00
handle multiple projects
This commit is contained in:
parent
3aa187c2c4
commit
7981e0aebc
20
src/drone.py
20
src/drone.py
@ -33,14 +33,24 @@ signal.signal(signal.SIGTERM, cleanup)
|
|||||||
|
|
||||||
def drone(ctx: WorkerContext):
|
def drone(ctx: WorkerContext):
|
||||||
global die
|
global die
|
||||||
|
|
||||||
|
sorted_projects = sorted(worker.get_project_list(), key=lambda p: p["priority"], reverse=True)
|
||||||
|
|
||||||
while not die:
|
while not die:
|
||||||
task = worker.fetch_task(1)
|
task = None
|
||||||
try:
|
try:
|
||||||
|
ok = False
|
||||||
|
for project in sorted_projects:
|
||||||
|
task = worker.fetch_task(project["id"])
|
||||||
if task is not None:
|
if task is not None:
|
||||||
with lock:
|
with lock:
|
||||||
current_tasks.add(task.id)
|
current_tasks.add(task.id)
|
||||||
ctx.execute_task(task)
|
ctx.execute_task(task)
|
||||||
else:
|
ok = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not ok:
|
||||||
|
print("No tasks, waiting")
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
finally:
|
finally:
|
||||||
with lock:
|
with lock:
|
||||||
@ -56,8 +66,10 @@ worker = Worker.from_file(api)
|
|||||||
if not worker:
|
if not worker:
|
||||||
worker = api.make_worker("drone")
|
worker = api.make_worker("drone")
|
||||||
worker.dump_to_file()
|
worker.dump_to_file()
|
||||||
worker.request_access(1, True, False)
|
projects = worker.get_project_list()
|
||||||
|
for project in projects:
|
||||||
|
r = worker.request_access(project["id"], assign=True, submit=False)
|
||||||
|
print("Request access for %d r=%s" % (project["id"], r.text))
|
||||||
|
|
||||||
print("Starting %d working contexts" % (THREAD_COUNT,))
|
print("Starting %d working contexts" % (THREAD_COUNT,))
|
||||||
for i in range(THREAD_COUNT):
|
for i in range(THREAD_COUNT):
|
||||||
|
@ -100,6 +100,9 @@ class Worker:
|
|||||||
"secret": self.secret_b64
|
"secret": self.secret_b64
|
||||||
}, out)
|
}, out)
|
||||||
|
|
||||||
|
def get_project_list(self):
|
||||||
|
return self._api.get_project_list(self).json()["content"]["projects"]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_file(api):
|
def from_file(api):
|
||||||
if os.path.exists("worker.json"):
|
if os.path.exists("worker.json"):
|
||||||
@ -200,6 +203,9 @@ class TaskTrackerApi:
|
|||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
return json.loads(r.text)["content"]["secret"]
|
return json.loads(r.text)["content"]["secret"]
|
||||||
|
|
||||||
|
def get_project_list(self, worker: Worker):
|
||||||
|
return self._http_get("/project/list", worker)
|
||||||
|
|
||||||
def _http_get(self, endpoint: str, worker: Worker = None):
|
def _http_get(self, endpoint: str, worker: Worker = None):
|
||||||
if worker is not None:
|
if worker is not None:
|
||||||
headers = format_headers(secret=worker.secret_b64, wid=worker.id)
|
headers = format_headers(secret=worker.secret_b64, wid=worker.id)
|
||||||
|
@ -3,6 +3,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import traceback
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
|
|
||||||
from tt_drone.api import (Project, Worker, Task)
|
from tt_drone.api import (Project, Worker, Task)
|
||||||
@ -62,7 +63,10 @@ class WorkerContext:
|
|||||||
"verification"] if "verification" in json_result else 0).text
|
"verification"] if "verification" in json_result else 0).text
|
||||||
+ "for result" + result)
|
+ "for result" + result)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print(str(e) + traceback.format_exc())
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
print(path + "/run doesn't exist!")
|
||||||
|
|
||||||
def _do_post_task_hooks(self, res):
|
def _do_post_task_hooks(self, res):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user