1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
44 STATUS2TEXT = { 0:"UNDEFINED", 1:"ACCEPTED", 2:"SCHEDULED", 3:"RUNNING", 4:"PAUSED", 5:"FINISHED", 6:"FAILED" }
45
46
47 STATUS2COLOR = { 0:"magenta", 1:"brown", 2:"darkcyan", 3:"green", 4:"maroon", 5:"blue", 6:"red" }
48
49
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
80
81 - def __str__( self ) : return unicode(self).encode("utf8")
82
84
85
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
105
108
109 - def __str__( self ) : return unicode(self).encode("utf8")
110
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
127
128 - def __str__( self ) : return unicode(self).encode("utf8")
129
131
132
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
150
158
159 - def __str__( self ) : return unicode(self).encode("utf8")
160
162
163
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
178
179 - def __str__( self ) : return unicode(self).encode("utf8")
180
182
183
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 )
195
197
199
201