Package eoxserver :: Package resources :: Package processes :: Module models
[hide private]
[frames] | no frames]

Source Code for Module eoxserver.resources.processes.models

  1  #----------------------------------------------------------------------- 
  2  # $Id: models.py 1531 2012-03-15 11:23:26Z martin.paces $ 
  3  # 
  4  # Description:  
  5  # 
  6  #  processes - django DB model  
  7  # 
  8  #------------------------------------------------------------------------------- 
  9  # 
 10  # Project: EOxServer <http://eoxserver.org> 
 11  # Authors: Martin Paces <martin.paces@iguassu.cz> 
 12  # 
 13  #------------------------------------------------------------------------------- 
 14  # Copyright (C) 2011 Iguassu Software Systems, a.s  
 15  # 
 16  # Permission is hereby granted, free of charge, to any person obtaining a copy 
 17  # of this software and associated documentation files (the "Software"), to deal 
 18  # in the Software without restriction, including without limitation the rights 
 19  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
 20  # copies of the Software, and to permit persons to whom the Software is  
 21  # furnished to do so, subject to the following conditions: 
 22  # 
 23  # The above copyright notice and this permission notice shall be included in all 
 24  # copies of this Software or works derived from this Software. 
 25  # 
 26  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 27  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 28  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 29  # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 30  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 31  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
 32  # THE SOFTWARE. 
 33  #------------------------------------------------------------------------------- 
 34  """This module contains the process tracker Django DB model. Process tracker  
 35  is an essential part of the ATP (Asynchronous Task Processing) subsystem. """ 
 36   
 37  #------------------------------------------------------------------------------- 
 38   
 39  from django.db import models 
 40   
 41  #------------------------------------------------------------------------------- 
 42   
 43  #: status code to text conversion dictionary 
 44  STATUS2TEXT  = { 0:"UNDEFINED", 1:"ACCEPTED", 2:"SCHEDULED", 3:"RUNNING", 4:"PAUSED", 5:"FINISHED", 6:"FAILED" }  
 45   
 46  #: status code to color conversion dictionary 
 47  STATUS2COLOR = { 0:"magenta", 1:"brown", 2:"darkcyan", 3:"green", 4:"maroon", 5:"blue", 6:"red" }  
 48   
 49  #: status text to code reverse conversion dictionary (filled dynamically)  
 50  TEXT2STATUS  = dict( map( lambda item : ( item[1] , item[0] ) , STATUS2TEXT.items() ) ) 
 51   
 52  #------------------------------------------------------------------------------- 
 53   
54 -class Type( models.Model ) :
55 """ 56 Task Type. 57 58 DB fields: 59 identifier - process class ID; 60 handler - python dot path to handler function; 61 timeout - time in second after which the unfinished process is 62 considered to be abandoned and it is restarted 63 (number of restarts is limited by maxstart, default timeout is 3600 s); 64 timeret - retention time - period of time to keep finished processes 65 in case of zero or negative value the results will be kept forever 66 (default is -1); 67 maxstart - max. number of attempt to execute the task (first run and possible restarts) 68 When the number of (re)starts is exceeded the task is marked as failed 69 and rejected from further processing. (default is 3). 70 71 """ 72 identifier = models.CharField( max_length=64 , unique=True , blank=False , null=False, editable = False ) 73 handler = models.CharField( max_length=1024 , blank=False , null=False, editable = False ) 74 maxstart = models.IntegerField( default = 3 , blank = False , null = False , editable = False ) 75 timeout = models.FloatField( default = 3600.0 , blank = False , null = False , editable = False ) 76 timeret = models.FloatField( default = -1.0 , blank = False , null = False , editable = False ) 77
78 - def __unicode__( self ) :
79 return unicode( self.identifier )
80
81 - def __str__( self ) : return unicode(self).encode("utf8")
82
83 - class Admin : pass
84 85
86 -class Instance( models.Model ) :
87 """ 88 Task Instance. 89 90 DB fields: 91 type - process class of this instance; 92 identifier - process instance ID; 93 status - current status of the process; 94 timeInsert - instance creation time (aka enqueue or insert time ); 95 timeUpdate - instance last status update time. 96 97 """ 98 type = models.ForeignKey( Type , blank=False , null=False , editable = False , on_delete = models.PROTECT ) 99 identifier = models.CharField( max_length=64 , blank=False , null=False, editable = False ) 100 timeInsert = models.DateTimeField( auto_now_add=True , editable = False ) 101 timeUpdate = models.DateTimeField( auto_now=True , editable = False ) 102 status = models.IntegerField( null=False , editable = False ) 103
104 - class Meta: unique_together = (('identifier','type'),)
105
106 - def __unicode__( self ) :
107 return u"%s::%s"%( self.type.identifier , self.identifier )
108
109 - def __str__( self ) : return unicode(self).encode("utf8")
110
111 - class Admin : pass
112 113
114 -class Task( models.Model ):
115 """ 116 Task queue. 117 118 DB fields: 119 instance - process instance. 120 """ 121 instance = models.ForeignKey( Instance , blank=False , null=False , editable = False ) 122 time = models.DateTimeField( auto_now=True, editable = False ) 123 lock = models.BigIntegerField( default = 0 ) 124
125 - def __unicode__( self ) :
126 return u"%s::%s"%( self.instance.type.identifier , self.instance.identifier )
127
128 - def __str__( self ) : return unicode(self).encode("utf8")
129
130 - class Admin : pass
131 132
133 -class LogRecord( models.Model ):
134 """ 135 Task status change Log. 136 137 DB fields: 138 instance - process instance; 139 time - time-stamp of the log record; 140 status - status code of the process instance; 141 message - text message associated to the log message. 142 143 """ 144 instance = models.ForeignKey( Instance , blank=False , null=False , editable = False ) 145 time = models.DateTimeField( auto_now=True, editable = False ) 146 status = models.IntegerField( null=False , choices = STATUS2TEXT.items(), editable = False ) 147 message = models.TextField( editable = False ) 148 149 # pid - local process ID 150
151 - def __unicode__( self ) :
152 153 message = unicode(self.message) 154 if ( 28 < len(message) ) : 155 message = u"%s ..."%message[:28] 156 157 return u'%22.22s [%s] %s\t%s' % ( self.time , self.instance , STATUS2TEXT[self.status] , message )
158
159 - def __str__( self ) : return unicode(self).encode("utf8")
160
161 - class Admin : pass
162 163
164 -class Response( models.Model ):
165 """ 166 Task Response storage. 167 168 DB fields: 169 instance - process instance; 170 response - process XML response (if not in plain text GZIP+BASE64 is applied). 171 172 """ 173 instance = models.ForeignKey( Instance , blank=False , null=False , editable = False , unique = True ) 174 response = models.TextField( editable = False ) 175 mimeType = models.TextField( editable = True ) 176
177 - def __unicode__( self ) : return unicode( self.instance )
178
179 - def __str__( self ) : return unicode(self).encode("utf8")
180
181 - class Admin : pass
182 183
184 -class Input( models.Model ):
185 """ 186 Process Input storage. 187 188 DB fields: 189 instance - process instance; 190 input - task inputs. 191 192 """ 193 instance = models.ForeignKey( Instance , blank=False , null=False , editable = False , unique = True ) 194 input = models.TextField( editable = False ) # store the data as Base64 encoded pickle object 195
196 - def __unicode__( self ) : return unicode( self.instance )
197
198 - def __str__( self ) : return unicode(self).encode("utf8")
199
200 - class Admin : pass
201