app/soc/models/job.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sat, 18 Apr 2009 14:03:28 +0000
changeset 2209 989c7c945d5f
child 2212 4095892a3c99
permissions -rw-r--r--
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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2209
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""This module contains the Job Model."""
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
__authors__ = [
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
]
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
from google.appengine.ext import db
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
from django.utils.translation import ugettext
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from soc.models import base
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from soc.models import priority_group
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
class Job(base.ModelWithFieldAttributes):
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
  """The Job model.
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
  """
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
  #: reference to the priority group this job belongs to
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
  priority_group = db.ReferenceProperty(
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
      reference_class=priority_group.PriorityGroup, required=True,
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
      collection_name='jobs')
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
  #: the name of the task as defined in soc.cron.job
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
  task_name = db.StringProperty(required=True)
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
  #: field storing the status of this job
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
  #: Waiting means that this job is waiting to be run.
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
  #: Started means that this job has a worker that is running it.
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
  #: Finished means that this job has been completed.
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
  #: Aborted means that this job has been aborted due to a fatal error.
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
  status = db.StringProperty(default='waiting',
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
      choices=['waiting','started','finished', 'aborted'])
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
  #: the date this job was last modified on
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
  last_modified_on = db.DateTimeProperty(auto_now_add=True)
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
  #: the amount of times this job raised an Exception (other than an
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
  #: DeadlineExceededException).
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
  errors = db.IntegerProperty(default=0)
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
  #: the data that the worker will use to process this job
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
  text_data = db.TextProperty(required=False, default="")
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    62
  #: the data that the worker will use to process this job
989c7c945d5f Add jobs (model, logic, and view)
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
  key_data = db.ListProperty(db.Key, default=[])