app/soc/logic/system.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sun, 19 Apr 2009 17:42:44 +0000
changeset 2246 c29272f640b0
parent 1797 f0c83ca3bb08
child 2865 fee8732830f7
permissions -rw-r--r--
Tweak the 'load balancing' algorithm In order to reduce contention we randomly skipped jobs, but this caused many jobs to end up stopping early. Now instead we keep on going until we time out (also increased the chance of doing work). Patch by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
114
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1307
diff changeset
     3
# Copyright 2008 the Melange authors.
114
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
"""Basic system information functions.
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
"""
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
__authors__ = [
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    21
  '"Todd Larsen" <tlarsen@google.com>',
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    22
  ]
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
578
0f34318f5693 Add release tag string, Melange "badge" image, and Google App Engine version
Todd Larsen <tlarsen@google.com>
parents: 114
diff changeset
    25
import os
114
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    26
import settings
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    27
9998e95ce609 A collection of functions for determining the characteristics of the "system"
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    28
578
0f34318f5693 Add release tag string, Melange "badge" image, and Google App Engine version
Todd Larsen <tlarsen@google.com>
parents: 114
diff changeset
    29
def getAppVersion():
0f34318f5693 Add release tag string, Melange "badge" image, and Google App Engine version
Todd Larsen <tlarsen@google.com>
parents: 114
diff changeset
    30
  """Returns the Google App Engine "version" of the running instance.
0f34318f5693 Add release tag string, Melange "badge" image, and Google App Engine version
Todd Larsen <tlarsen@google.com>
parents: 114
diff changeset
    31
  """
1592
4465cda55182 Add a maintenance end date
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
    32
578
0f34318f5693 Add release tag string, Melange "badge" image, and Google App Engine version
Todd Larsen <tlarsen@google.com>
parents: 114
diff changeset
    33
  return os.environ.get('CURRENT_VERSION_ID')
1797
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    34
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    35
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    36
def getMelangeVersion():
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    37
  """Returns the Melange part of the GAE version.
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    38
  """
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    39
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    40
  return getAppVersion().split('.', 1)[0]
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    41
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    42
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    43
def isLocal():
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    44
  """Returns True if Melange application is running locally.
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    45
  
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    46
  "Local mode" is currently determined from settings.DEBUG but may become
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    47
  more sophisticated in the future.
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    48
  """
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    49
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    50
  return settings.DEBUG
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    51
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    52
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    53
def isDebug():
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    54
  """Returns True if Melange application is running in "debug mode".
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    55
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    56
  "Debug mode" is currently enabled if running locally or if the
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    57
  current Melange version is 'devvin'.
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    58
  """
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    59
f0c83ca3bb08 isDebug now also checks melange version
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1592
diff changeset
    60
  return isLocal() or getMelangeVersion() == 'devvin'