@@ -20,7 +20,17 @@ class SGEPlugin(SGELikeBatchManagerBase):
20
20
"""
21
21
22
22
def __init__ (self , ** kwargs ):
23
- template = """#$ -V\n #$ -S /bin/sh\n """
23
+ template = """
24
+ #$ -V
25
+ #$ -S /bin/sh
26
+ """
27
+ self ._retry_timeout = 2
28
+ self ._max_tries = 2
29
+ if 'plugin_args' in kwargs and kwargs ['plugin_args' ]:
30
+ if 'retry_timeout' in kwargs ['plugin_args' ]:
31
+ self ._retry_timeout = kwargs ['plugin_args' ]['retry_timeout' ]
32
+ if 'max_tries' in kwargs ['plugin_args' ]:
33
+ self ._max_tries = kwargs ['plugin_args' ]['max_tries' ]
24
34
super (SGEPlugin , self ).__init__ (template , ** kwargs )
25
35
26
36
def _is_pending (self , taskid ):
@@ -55,16 +65,24 @@ def _submit_batchtask(self, scriptfile, node):
55
65
scriptfile )
56
66
oldlevel = iflogger .level
57
67
iflogger .setLevel (logging .getLevelName ('CRITICAL' ))
58
- try :
59
- result = cmd .run ()
60
- except Exception , e :
61
- iflogger .setLevel (oldlevel )
62
- raise RuntimeError ('\n ' .join (('Could not submit sge task for node %s' % node ._id ,
63
- str (e ))))
64
- else :
65
- iflogger .setLevel (oldlevel )
66
- # retrieve sge taskid
67
- taskid = int (result .runtime .stdout .split (' ' )[2 ])
68
- self ._pending [taskid ] = node .output_dir ()
69
- logger .debug ('submitted sge task: %d for node %s' % (taskid , node ._id ))
68
+ tries = 0
69
+ while True :
70
+ try :
71
+ result = cmd .run ()
72
+ except Exception , e :
73
+ if tries < self ._max_tries :
74
+ tries += 1
75
+ sleep (self ._retry_timeout ) # sleep 2 seconds and try again.
76
+ else :
77
+ iflogger .setLevel (oldlevel )
78
+ raise RuntimeError ('\n ' .join ((('Could not submit sge task'
79
+ ' for node %s' ) % node ._id ,
80
+ str (e ))))
81
+ else :
82
+ break
83
+ iflogger .setLevel (oldlevel )
84
+ # retrieve sge taskid
85
+ taskid = int (result .runtime .stdout .split (' ' )[2 ])
86
+ self ._pending [taskid ] = node .output_dir ()
87
+ logger .debug ('submitted sge task: %d for node %s' % (taskid , node ._id ))
70
88
return taskid
0 commit comments