Add jobs (model, logic, and view)
authorSverre Rabbelier <srabbelier@gmail.com>
Sat, 18 Apr 2009 14:03:28 +0000
changeset 2209 989c7c945d5f
parent 2208 1bf4e904d5f5
child 2210 1095b52ed667
Add jobs (model, logic, and view) Jobs are the core of the Job system, allowing distributed processing of taks in an interuptable manner. Patch by: Sverre Rabbelier
app/soc/logic/models/job.py
app/soc/models/job.py
app/soc/templates/soc/job/list/heading.html
app/soc/templates/soc/job/list/row.html
app/soc/templates/soc/job/public.html
app/soc/views/models/job.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/logic/models/job.py	Sat Apr 18 14:03:28 2009 +0000
@@ -0,0 +1,43 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2009 the Melange authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Job (Model) query functions.
+"""
+
+__authors__ = [
+  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
+  ]
+
+
+from soc.logic.models import base
+
+import soc.models.job
+
+
+class Logic(base.Logic):
+  """Logic methods for the Job model.
+  """
+
+  def __init__(self, model=soc.models.job.Job,
+               base_model=None, scope_logic=None):
+    """Defines the name, key_name and model for this entity.
+    """
+
+    super(Logic, self).__init__(model=model, base_model=base_model,
+                                scope_logic=scope_logic, id_based=True)
+
+
+logic = Logic()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/models/job.py	Sat Apr 18 14:03:28 2009 +0000
@@ -0,0 +1,63 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2009 the Melange authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""This module contains the Job Model."""
+
+__authors__ = [
+  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
+]
+
+
+from google.appengine.ext import db
+
+from django.utils.translation import ugettext
+
+from soc.models import base
+from soc.models import priority_group
+
+
+class Job(base.ModelWithFieldAttributes):
+  """The Job model.
+  """
+
+  #: reference to the priority group this job belongs to
+  priority_group = db.ReferenceProperty(
+      reference_class=priority_group.PriorityGroup, required=True,
+      collection_name='jobs')
+
+  #: the name of the task as defined in soc.cron.job
+  task_name = db.StringProperty(required=True)
+
+  #: field storing the status of this job
+  #: Waiting means that this job is waiting to be run.
+  #: Started means that this job has a worker that is running it.
+  #: Finished means that this job has been completed.
+  #: Aborted means that this job has been aborted due to a fatal error.
+  status = db.StringProperty(default='waiting',
+      choices=['waiting','started','finished', 'aborted'])
+
+  #: the date this job was last modified on
+  last_modified_on = db.DateTimeProperty(auto_now_add=True)
+
+  #: the amount of times this job raised an Exception (other than an
+  #: DeadlineExceededException).
+  errors = db.IntegerProperty(default=0)
+
+  #: the data that the worker will use to process this job
+  text_data = db.TextProperty(required=False, default="")
+
+  #: the data that the worker will use to process this job
+  key_data = db.ListProperty(db.Key, default=[])
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/job/list/heading.html	Sat Apr 18 14:03:28 2009 +0000
@@ -0,0 +1,5 @@
+<tr align="left">
+  <th>Link ID</th>
+  <th>Name</th>
+  <th>Priority</th>
+</tr>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/job/list/row.html	Sat Apr 18 14:03:28 2009 +0000
@@ -0,0 +1,10 @@
+<tr class="off" onmouseover="this.className='on'" onmouseout="this.className='off'"
+onclick="document.location.href='{{ list.redirect }}'" name="name">
+  <td align="right">
+   <div class="link_id">
+    <a class="noul"
+     href="{{ list.redirect }}">{{ list.item.link_id }}</a>
+   </div>
+  </td>
+  <td><div class="name">{{ list.item.name }}</div></td>
+</tr>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/job/public.html	Sat Apr 18 14:03:28 2009 +0000
@@ -0,0 +1,24 @@
+{% extends "soc/base.html" %}
+{% comment %}
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+{% load forms_helpers %}
+
+{% block body %}
+<p>
+ <table>
+  {% readonly_field_as_table_row "id" entity.key.id %}
+  {% readonly_field_as_table_row entity.fields.status.label entity.status %}
+ </table>
+</p>
+{% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/views/models/job.py	Sat Apr 18 14:03:28 2009 +0000
@@ -0,0 +1,77 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2009 the Melange authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Views for Jobs.
+"""
+
+__authors__ = [
+    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
+  ]
+
+
+from django import forms
+
+from soc.logic import cleaning
+from soc.logic import dicts
+from soc.logic.models.job import logic as job_logic
+from soc.views.helper import access
+from soc.views.helper import decorators
+from soc.views.helper import dynaform
+from soc.views.helper import widgets
+from soc.views.models import base
+
+
+class View(base.View):
+  """View methods for the Job model.
+  """
+
+  def __init__(self, params=None):
+    """Defines the fields and methods required for the base View class
+    to provide the user with list, public, create, edit and delete views.
+
+    Params:
+      params: a dict with params for this View
+    """
+
+    rights = access.Checker(params)
+
+    new_params = {}
+    new_params['rights'] = rights
+    new_params['logic'] = job_logic
+
+    new_params['name'] = "Job"
+
+    new_params['no_create_raw'] = True
+    new_params['no_create_with_scope'] = True
+    new_params['no_create_with_key_fields'] = True
+
+    new_params['extra_dynaexclude'] = ['key_data', 'text_data']
+
+    new_params['edit_dynaproperties'] = {
+      'task': forms.CharField(widget=widgets.PlainTextWidget()),
+      }
+
+    params = dicts.merge(params, new_params)
+
+    super(View, self).__init__(params=params)
+
+
+view = View()
+
+delete = decorators.view(view.delete)
+edit = decorators.view(view.edit)
+list = decorators.view(view.list)
+public = decorators.view(view.public)