This repository has been archived by the owner on Aug 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsubmission.py
58 lines (47 loc) · 1.72 KB
/
submission.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
import logging
import tmlib.models as tm
class SubmissionManager(object):
'''Mixin class for submission and monitoring of computational tasks.'''
def __init__(self, experiment_id, program_name):
'''
Parameters
----------
experiment_id: int
ID of the processed experiment
program_name: str
name of the submitting program
'''
self.experiment_id = experiment_id
self.program_name = program_name
def register_submission(self, user_id=None):
'''Creates a database entry in the "submissions" table.
Parameters
----------
user_id: int, optional
ID of submitting user (if not the user who owns the experiment)
Returns
-------
Tuple[int, str]
ID of the submission and the name of the submitting user
Warning
-------
Ensure that the "submissions" table get updated once the jobs
were submitted, i.e. added to a running `GC3Pie` engine.
To this end, use the ::meth:`tmlib.workflow.api.update_submission`
method.
See also
--------
:class:`tmlib.models.submission.Submission`
'''
with tm.utils.MainSession() as session:
if user_id is None:
experiment = session.query(tm.ExperimentReference).\
get(self.experiment_id)
user_id = experiment.user_id
submission = tm.Submission(
experiment_id=self.experiment_id, program=self.program_name,
user_id=user_id
)
session.add(submission)
session.commit()
return (submission.id, submission.user.name)