mirror of
https://github.com/clearml/clearml-server
synced 2025-01-31 02:46:53 +00:00
Add task diff support
This commit is contained in:
parent
566b28dc4c
commit
a33c94e24f
@ -29,6 +29,7 @@ class TaskStatus(object):
|
||||
published = 'published'
|
||||
closed = 'closed'
|
||||
failed = 'failed'
|
||||
completed = 'completed'
|
||||
unknown = 'unknown'
|
||||
|
||||
|
||||
@ -49,6 +50,7 @@ class Script(EmbeddedDocument):
|
||||
entry_point = StringField(required=True)
|
||||
working_dir = StringField()
|
||||
requirements = SafeDictField()
|
||||
diff = StringField()
|
||||
|
||||
|
||||
class Execution(EmbeddedDocument):
|
||||
|
38
server/tests/automated/test_tasks_diff.py
Normal file
38
server/tests/automated/test_tasks_diff.py
Normal file
@ -0,0 +1,38 @@
|
||||
from config import config
|
||||
from tests.automated import TestService
|
||||
|
||||
log = config.logger(__file__)
|
||||
|
||||
|
||||
class TestTasksDiff(TestService):
|
||||
|
||||
def setUp(self, version="2.0"):
|
||||
super(TestTasksDiff, self).setUp(version=version)
|
||||
|
||||
def new_task(self, **kwargs):
|
||||
return self.create_temp(
|
||||
"tasks", name="test", type="testing", input=dict(view=dict()), **kwargs
|
||||
)
|
||||
|
||||
def _compare_script(self, task, script):
|
||||
for key, value in script.items():
|
||||
self.assertEqual(task.script[key], value)
|
||||
|
||||
def test_not_deleted(self):
|
||||
task_id = self.new_task()
|
||||
script = dict(
|
||||
requirements=dict(pip=["six"]),
|
||||
repository="https://example.come/foo/bar",
|
||||
entry_point="test.py",
|
||||
diff="foo",
|
||||
)
|
||||
self.api.tasks.edit(task=task_id, script=script)
|
||||
self.api.tasks.started(task=task_id)
|
||||
self.api.tasks.reset(task=task_id)
|
||||
task = self.api.tasks.get_by_id(task=task_id).task
|
||||
self._compare_script(task, script)
|
||||
new_reqs = dict()
|
||||
self.api.tasks.set_requirements(task=task_id, requirements=new_reqs)
|
||||
script["requirements"] = new_reqs
|
||||
task = self.api.tasks.get_by_id(task=task_id).task
|
||||
self._compare_script(task, script)
|
29
server/utilities/threads_manager.py
Normal file
29
server/utilities/threads_manager.py
Normal file
@ -0,0 +1,29 @@
|
||||
from functools import wraps
|
||||
from threading import Lock, Thread
|
||||
|
||||
import attr
|
||||
|
||||
|
||||
@attr.s(auto_attribs=True)
|
||||
class ThreadsManager:
|
||||
objects = {}
|
||||
lock = Lock()
|
||||
|
||||
def register(self, thread_name, daemon=True):
|
||||
def decorator(f):
|
||||
@wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
with self.lock:
|
||||
thread = self.objects.get(thread_name)
|
||||
if not thread:
|
||||
thread = Thread(
|
||||
target=f, name=thread_name, args=args, kwargs=kwargs
|
||||
)
|
||||
thread.daemon = daemon
|
||||
thread.start()
|
||||
self.objects[thread_name] = thread
|
||||
return thread.ident
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
Loading…
Reference in New Issue
Block a user