Skip to content

Commit

Permalink
Merge 96f3ff9 into b676ab2
Browse files Browse the repository at this point in the history
  • Loading branch information
guidow committed Jun 15, 2015
2 parents b676ab2 + 96f3ff9 commit f3d73b6
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 5 deletions.
5 changes: 5 additions & 0 deletions pyfarm/master/api/jobtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def schema():
"id": "INTEGER",
"version": "INTEGER",
"max_batch": "INTEGER",
"no_automatic_start_time": "INTEGER",
"name": "VARCHAR(64)"
}
Expand Down Expand Up @@ -243,6 +244,8 @@ def post(self):
jobtype_version.classname = g.json.pop("classname", None)
jobtype_version.batch_contiguous = g.json.pop("batch_contiguous",
None)
jobtype_version.no_automatic_start_time = g.json.pop(
"no_automatic_start_time", None)
if "max_batch" in g.json and g.json["max_batch"] is None:
g.json.pop("max_batch")
jobtype_version.max_batch = sql.null()
Expand Down Expand Up @@ -492,6 +495,8 @@ def put(self, jobtype_name):
jobtype_version.classname = g.json.pop("classname", None)
jobtype_version.batch_contiguous = g.json.pop("batch_contiguous",
None)
jobtype_version.no_automatic_start_time =\
g.json.pop("no_automatic_start_time", None)
if "max_batch" in g.json and g.json["max_batch"] is None:
g.json.pop("max_batch")
jobtype_version.max_batch = sql.null()
Expand Down
12 changes: 12 additions & 0 deletions pyfarm/master/templates/pyfarm/user_interface/jobtype.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ <h1 style="margin-bottom:20px">{{ jobtype.name }}</h1>
{% endif %}
</td>
</tr>
<tr>
<td>
<label for="no_automatic_start_time">No Automatic Start Time</label>
</td>
<td>
{% if latest_version.no_automatic_start_time %}
<input type="checkbox" id="no_automatic_start_time" name="no_automatic_start_time" value="true" checked/>
{% else %}
<input type="checkbox" id="no_automatic_start_time" name="no_automatic_start_time" value="true"/>
{% endif %}
</td>
</tr>
<tr>
<td>
<label for="classname">Class Name</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
<input id="batch_contiguous" name="batch_contiguous" type="checkbox" value="true" checked/>
</div>
</div>
<div class="form-group">
<label for="no_automatic_start_time" class="col-sm-2 control-label">No Automatic Start Time</label>
<div class="col-sm-5">
<input id="no_automatic_start_time" name="batch_contiguous" type="checkbox" value="true"/>
</div>
</div>
<div class="form-group">
<label for="classname" class="col-sm-2 control-label">Class Name</label>
<div class="col-sm-5">
Expand Down
10 changes: 10 additions & 0 deletions pyfarm/master/user_interface/jobtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def jobtype(jobtype_id):
new_version.batch_contiguous =\
("batch_contiguous" in request.form and
request.form["batch_contiguous"] == "true")
new_version.no_automatic_start_time =\
("no_automatic_start_time" in request.form and
request.form["no_automatic_start_time"] == "true")
new_version.classname = request.form["classname"]
new_version.code = request.form["code"]

Expand Down Expand Up @@ -119,6 +122,8 @@ def remove_jobtype_software_requirement(jobtype_id, software_id):
new_version = JobTypeVersion(jobtype=jobtype)
new_version.max_batch = previous_version.max_batch or sql.null()
new_version.batch_contiguous = previous_version.batch_contiguous
new_version.no_automatic_start_time =\
previous_version.no_automatic_start_time
new_version.classname = previous_version.classname
new_version.code = previous_version.code
new_version.version = previous_version.version + 1
Expand Down Expand Up @@ -158,6 +163,8 @@ def add_jobtype_software_requirement(jobtype_id):
new_version = JobTypeVersion(jobtype=jobtype)
new_version.max_batch = previous_version.max_batch or sql.null()
new_version.batch_contiguous = previous_version.batch_contiguous
new_version.no_automatic_start_time =\
previous_version.no_automatic_start_time
new_version.classname = previous_version.classname
new_version.code = previous_version.code
new_version.version = previous_version.version + 1
Expand Down Expand Up @@ -259,6 +266,9 @@ def create_jobtype():
jobtype_version.batch_contiguous =\
("batch_contiguous" in request.form and
request.form["batch_contiguous"] == "true")
jobtype_version.no_automatic_start_time =\
("no_automatic_start_time" in request.form and
request.form["no_automatic_start_time"] == "true")
jobtype_version.classname = request.form["classname"]
jobtype_version.code = request.form["code"]

Expand Down
8 changes: 8 additions & 0 deletions pyfarm/models/jobtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ class JobTypeVersion(db.Model, UtilityMixins, ReprMixin):
"together but not 2, 4, 6, 8. If this column is False "
"however the queue will batch non-contiguous tasks too.")

no_automatic_start_time = db.Column(
db.Boolean,
nullable=False,
default=False,
doc="If set, we will not automatically set `time_started_on` "
"for the tasks in jobs of this type when they are set "
"to `running`.")

classname = db.Column(
db.String(config.get("job_type_max_class_name_length")),
nullable=True,
Expand Down
24 changes: 19 additions & 5 deletions pyfarm/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@
"""

from functools import partial
from datetime import datetime

from sqlalchemy import event

from pyfarm.core.logger import getLogger
from pyfarm.core.enums import WorkState
from pyfarm.core.enums import WorkState, _WorkState
from pyfarm.master.application import db
from pyfarm.master.config import config
from pyfarm.models.core.types import IDTypeAgent, IDTypeWork
from pyfarm.models.core.functions import work_columns, repr_enum
from pyfarm.models.core.mixins import (
ValidatePriorityMixin, WorkStateChangedMixin, UtilityMixins, ReprMixin,
ValidateWorkStateMixin)
ValidatePriorityMixin, UtilityMixins, ReprMixin, ValidateWorkStateMixin)

__all__ = ("Task", )

logger = getLogger("models.task")


class Task(db.Model, ValidatePriorityMixin, ValidateWorkStateMixin,
WorkStateChangedMixin, UtilityMixins, ReprMixin):
UtilityMixins, ReprMixin):
"""
Defines a task which a child of a :class:`Job`. This table represents
rows which contain the individual work unit(s) for a job.
Expand Down Expand Up @@ -170,8 +170,22 @@ def clear_error_state(target, new_value, old_value, initiator):
if new_value == WorkState.DONE and target.last_error is not None:
target.last_error = None

@staticmethod
def set_times(target, new_value, old_value, initiator):
"""update the datetime objects depending on the new value"""

if (new_value == _WorkState.RUNNING and
(old_value not in [_WorkState.RUNNING, _WorkState.PAUSED] or
target.time_started == None)):
if not target.job.jobtype_version.no_automatic_start_time:
target.time_started = datetime.utcnow()
target.time_finished = None

elif new_value in (_WorkState.DONE, _WorkState.FAILED):
target.time_finished = datetime.utcnow()

event.listen(Task.state, "set", Task.clear_error_state)
event.listen(Task.state, "set", Task.state_changed)
event.listen(Task.state, "set", Task.set_times)
event.listen(Task.state, "set", Task.update_failures)
event.listen(Task.state, "set", Task.set_progress_on_success)
event.listen(Task.agent_id, "set", Task.increment_attempts)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_master/test_jobtypes_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def test_jobtype_post(self):
self.assertEqual(
response2.json, {
"batch_contiguous": True,
"no_automatic_start_time": False,
"classname": None,
"code": code,
"description": "Jobtype for testing inserts and queries",
Expand All @@ -88,6 +89,7 @@ def test_jobtype_post(self):
self.assertEqual(
response3.json, {
"batch_contiguous": True,
"no_automatic_start_time": False,
"classname": None,
"code": code,
"description": "Jobtype for testing inserts and queries",
Expand Down Expand Up @@ -120,6 +122,7 @@ def test_jobtype_post_empty_max_batch(self):
self.assertEqual(
response2.json, {
"batch_contiguous": True,
"no_automatic_start_time": False,
"classname": None,
"code": code,
"description": "Jobtype for testing inserts and queries",
Expand Down Expand Up @@ -173,6 +176,7 @@ def test_jobtype_post_with_requirements(self):
response3.json, {
"batch_contiguous": True,
"classname": None,
"no_automatic_start_time": False,
"code": code,
"description": "Jobtype for testing inserts and queries",
"id": id,
Expand Down Expand Up @@ -321,6 +325,7 @@ def test_jobtype_put(self):
self.assertEqual(
response2.json, {
"batch_contiguous": True,
"no_automatic_start_time": False,
"classname": None,
"code": code,
"description": "Jobtype for testing inserts and queries",
Expand Down Expand Up @@ -364,6 +369,7 @@ def test_jobtype_put_overwrite(self):
self.assertEqual(
response3.json, {
"batch_contiguous": True,
"no_automatic_start_time": False,
"classname": None,
"code": code,
"description": "Jobtype for testing (updated)",
Expand Down Expand Up @@ -443,6 +449,7 @@ def test_jobtype_put_with_requirements(self):
self.assertEqual(
response3.json, {
"batch_contiguous": True,
"no_automatic_start_time": False,
"classname": None,
"code": code,
"description": "Jobtype for testing inserts and queries",
Expand Down Expand Up @@ -646,6 +653,7 @@ def test_jobtype_put_retain_requirements(self):
self.assertEqual(
response4.json, {
"batch_contiguous": True,
"no_automatic_start_time": False,
"classname": None,
"code": code,
"description": "Jobtype for testing (updated)",
Expand Down Expand Up @@ -819,6 +827,7 @@ def test_jobtype_get_versioned(self):
self.assertEqual(
response3.json, {
"batch_contiguous": True,
"no_automatic_start_time": False,
"classname": None,
"code": code,
"description": "Jobtype for testing inserts and queries",
Expand All @@ -838,6 +847,7 @@ def test_jobtype_get_versioned(self):
self.assertEqual(
response4.json, {
"batch_contiguous": True,
"no_automatic_start_time": False,
"classname": None,
"code": code,
"description": "Jobtype for testing inserts and queries",
Expand All @@ -857,6 +867,7 @@ def test_jobtype_get_versioned(self):
self.assertEqual(
response5.json, {
"batch_contiguous": True,
"no_automatic_start_time": False,
"classname": None,
"code": code,
"description": "Jobtype for testing inserts and queries",
Expand Down Expand Up @@ -924,6 +935,7 @@ def test_jobtype_delete_version(self):
self.assertEqual(
response5.json, {
"batch_contiguous": True,
"no_automatic_start_time": False,
"classname": None,
"code": code,
"description": "Jobtype for testing inserts and queries",
Expand Down Expand Up @@ -975,6 +987,7 @@ def test_jobtype_by_id_delete_version(self):
self.assertEqual(
response5.json, {
"batch_contiguous": True,
"no_automatic_start_time": False,
"classname": None,
"code": code,
"description": "Jobtype for testing inserts and queries",
Expand Down

0 comments on commit f3d73b6

Please sign in to comment.