Skip to content

Commit

Permalink
Merge pull request #529 from guidow/break_up_autodelete_time
Browse files Browse the repository at this point in the history
Break up autodelete time into d, h, m, s
  • Loading branch information
opalmer committed Aug 25, 2015
2 parents 15a527e + 0dbf459 commit f7143ea
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
11 changes: 7 additions & 4 deletions pyfarm/master/templates/pyfarm/user_interface/job.html
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,18 @@ <h4>Notified Users</h4>
</form>

<h4>Auto Deletion</h4>
<form method="POST" action="{{ url_for('alter_autodelete_parameters_in_job_ui', job_id=job.id) }}">
<form method="POST" action="{{ url_for('alter_autodelete_parameters_in_job_ui', job_id=job.id) }}" class="form-inline">
<table class="table">
<tbody>
<tr>
<td title="In seconds, leave blank to disable autodelete">
Autodelete After Seconds
<td title="Leave blank to disable autodelete">
Autodelete After
</td>
<td>
<input class="form-control" type="text" name="autodelete_time" value="{{ job.autodelete_time if job.autodelete_time else '' }}"/>
<input class="form-control" type="text" name="days" value="{{ autodelete_time.days if autodelete_time else '' }}" style="width:3em;"/> d
<input class="form-control" type="text" name="hours" value="{{ autodelete_time.hours if autodelete_time else '' }}" style="width:3em;"/> h
<input class="form-control" type="text" name="minutes" value="{{ autodelete_time.minutes if autodelete_time else '' }}" style="width:3em;"/> m
<input class="form-control" type="text" name="seconds" value="{{ autodelete_time.seconds if autodelete_time else '' }}" style="width:3em;"/> s
</td>
</tr>
<tr>
Expand Down
27 changes: 23 additions & 4 deletions pyfarm/master/user_interface/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.

from decimal import Decimal
from datetime import datetime
from datetime import datetime, timedelta

try:
from httplib import (
Expand Down Expand Up @@ -358,12 +358,22 @@ def single_job(job_id):
jobtype=job.jobtype_version.jobtype).\
order_by(desc(JobTypeVersion.version)).first()

autodelete_time = None
if job.autodelete_time:
autodelete_timedelta = timedelta(seconds=job.autodelete_time)
autodelete_time = {"days": autodelete_timedelta.days}
seconds = autodelete_timedelta.seconds
autodelete_time["hours"], remainder = divmod(seconds, 3600)
autodelete_time["minutes"], autodelete_time["seconds"] =\
divmod(remainder, 60)

return render_template("pyfarm/user_interface/job.html", job=job,
tasks=tasks, first_task=first_task,
last_task=last_task, queues=jobqueues,
users=users_query,
latest_jobtype_version=latest_jobtype_version[0],
now=datetime.utcnow())
now=datetime.utcnow(),
autodelete_time=autodelete_time)

def delete_single_job(job_id):
job = Job.query.filter_by(id=job_id).first()
Expand Down Expand Up @@ -892,8 +902,17 @@ def alter_autodeletion_for_job(job_id):
"pyfarm/error.html", error="Job %s not found" % job_id),
NOT_FOUND)

if request.form['autodelete_time']:
job.autodelete_time = int(request.form['autodelete_time'])
days = int(request.form["days"] or 0)
hours = int(request.form["hours"] or 0)
minutes = int(request.form["minutes"] or 0)
seconds = int(request.form["seconds"] or 0)

autodelete_time = timedelta(days=days, hours=hours, minutes=minutes,
seconds=seconds)
if autodelete_time.total_seconds() > 0:
job.autodelete_time = autodelete_time.total_seconds()
else:
job.autodelete_time = None

db.session.add(job)
db.session.commit()
Expand Down

0 comments on commit f7143ea

Please sign in to comment.