app/soc/cron/job.py
author Lennard de Rijk <ljvderijk@gmail.com>
Sat, 18 Apr 2009 15:06:36 +0000
changeset 2219 6f835882160e
parent 2217 2c6ec0357149
child 2224 fc719e902a70
permissions -rw-r--r--
Fixed typo and added myself to authors in the cron/job module. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2211
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""Cron jobs.
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
2219
6f835882160e Fixed typo and added myself to authors in the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2217
diff changeset
    22
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
2211
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
  ]
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
import logging
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from google.appengine.ext import db
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from google.appengine.runtime import DeadlineExceededError
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
from soc.models.job import Job
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
2217
2c6ec0357149 Added FatalJobError to the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2213
diff changeset
    34
class Error(Exception):
2c6ec0357149 Added FatalJobError to the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2213
diff changeset
    35
  """Base class for all exceptions raised by this module.
2c6ec0357149 Added FatalJobError to the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2213
diff changeset
    36
  """
2c6ec0357149 Added FatalJobError to the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2213
diff changeset
    37
  pass
2c6ec0357149 Added FatalJobError to the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2213
diff changeset
    38
2c6ec0357149 Added FatalJobError to the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2213
diff changeset
    39
2c6ec0357149 Added FatalJobError to the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2213
diff changeset
    40
class FatalJobError(Error):
2c6ec0357149 Added FatalJobError to the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2213
diff changeset
    41
  """Class for all errors that lead to immediate job abortion.
2c6ec0357149 Added FatalJobError to the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2213
diff changeset
    42
  """
2c6ec0357149 Added FatalJobError to the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2213
diff changeset
    43
  pass
2c6ec0357149 Added FatalJobError to the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2213
diff changeset
    44
2c6ec0357149 Added FatalJobError to the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2213
diff changeset
    45
2211
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
class Handler(object):
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
  """A handler that dispatches a cron job.
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
  The tasks that are mapped into tasks will be called when a worker
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
  has claimed the job. However, there is no guarantee as to how long
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
  the task will be allowed to run. If an Exception is raised the task
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
  is automatically rescheduled for execution.
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
  """
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
  def __init__(self):
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
    """Constructs a new Handler with all known jobs set.
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
    """
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
    self.tasks = {}
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
    self.tasks['sendAcceptanceEmail'] = logging.info
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    62
  def claimJob(self, job_key):
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
    """A transaction to claim a job.
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
    """
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
    job = Job.get_by_id(job_key)
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    67
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
    if job.status != 'waiting':
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
      raise db.Rollback()
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    70
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    71
    job.status = 'started'
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
    if job.put():
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
      return job
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    75
    else:
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    76
      return None
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
  def freeJob(self, job_key):
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    79
    """A transaction to free a job.
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
    """
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    81
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    82
    job = Job.get_by_id(job_key)
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    83
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    84
    job.status = 'waiting'
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    85
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    86
    return job.put()
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    88
  def failJob(self, job_key):
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    89
    """A transaction to fail a job.
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    90
    """
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    91
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    92
    job = Job.get_by_id(job_key)
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    93
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    94
    job.errors += 1
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    95
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    96
    if job.errors > 5:
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    97
      job.status = 'aborted'
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    98
    else:
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    99
      job.status = 'waiting'
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   100
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   101
    job_id = job.key().id()
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   102
    logging.warning("job %d now failed %d time(s)" % (job_id, job.errors))
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   103
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   104
    return job.put()
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   105
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   106
  def finishJob(self, job_key):
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   107
    """A transaction to finish a job.
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   108
    """
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   109
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   110
    job = Job.get_by_id(job_key)
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   111
    job.status = 'finished'
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   112
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   113
    return job.put()
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   114
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   115
  def abortJob(self, job_key):
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   116
    """A transaction to abort a job.
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   117
    """
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   118
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   119
    job = Job.get_by_id(job_key)
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   120
    job.status = 'aborted'
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   122
    return job.put()
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   123
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   124
  def handle(self, job_key):
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   125
    """Handle one job.
2213
c0f52da7a808 Remove testing method and update docstring for cron system
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2211
diff changeset
   126
c0f52da7a808 Remove testing method and update docstring for cron system
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2211
diff changeset
   127
    Returns: whether another job should be started after this one
2211
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   128
    """
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   129
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   130
    try:
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   131
      job = db.run_in_transaction(self.claimJob, job_key)
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   132
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   133
      if not job:
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   134
        # someone already claimed the job
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   135
        return True
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   136
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   137
      if job.task_name not in self.tasks:
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   138
        logging.error("Unknown job %s" % job.task_name)
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   139
        db.run_in_transaction(self.abortJob, job_key)
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   140
        return True
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   141
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   142
      task = self.tasks[job.task_name]
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   143
2219
6f835882160e Fixed typo and added myself to authors in the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2217
diff changeset
   144
      # execute the actual job
2211
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   145
      task(job)
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   146
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   147
      db.run_in_transaction(self.finishJob, job_key)
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   148
      return True
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   149
    except DeadlineExceededError, exception:
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   150
      db.run_in_transaction(self.freeJob, job_key)
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   151
      return False
2217
2c6ec0357149 Added FatalJobError to the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2213
diff changeset
   152
    except FatalJobError, exception:
2c6ec0357149 Added FatalJobError to the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2213
diff changeset
   153
      logging.exception(exception)
2c6ec0357149 Added FatalJobError to the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2213
diff changeset
   154
      db.run_in_transaction(self.abortJob, job_key)
2c6ec0357149 Added FatalJobError to the cron/job module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2213
diff changeset
   155
      return True
2211
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   156
    except Exception, exception:
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   157
      logging.exception(exception)
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   158
      db.run_in_transaction(self.failJob, job_key)
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   159
      return True
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   160
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   161
f7497180d037 Add cron, the core of the job system
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   162
handler = Handler()