CMS 3D CMS Logo

cmsStageWithFailover.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 #this script runs cmsStage multiple times in the case where it failes for some reason
4 
5 from __future__ import print_function
6 from builtins import range
7 if __name__ == '__main__':
8 
9  import PhysicsTools.HeppyCore.utils.eostools as eostools
11 
12  from cmsIO import *
13  from cmsStage import *
14 
15  import sys, time
16 
17  #this taken from the main of cmsStage
18  argv = sys.argv[1:]
19  (args, debug, force ) = parseOpts( argv )
20 
21  if not os.path.isfile(args[0]):
22  print(args[0], 'does not exist.')
23  sys.exit(1)
24  source = cmsFile( args[0], "rfio" )
25  destination = cmsFile( args[1], "stageout" )
26  checkArgs( source, destination, force )
27 
28  #find the destination LFN
29  dest = args[1]
30  if eostools.isDirectory(dest):
31  dest = os.path.join(dest,os.path.basename(args[0]))
32 
33  sleep_lengths = [1,10,60,600,1800]
34  return_code = 0
35  for i in range(5):
36 
37  #sleep for a while before running
38  time.sleep(sleep_lengths[i])
39 
40  try:
41  #run cmsStage
42  print('cmsStage %s [%d/5]' % (' '.join(argv) , i+1))
43  main(argv)
44 
45  except SystemExit as e:
46  print("cmsStage exited with code '%s'. Retrying... [%d/5]" % ( str(e), i+1 ))
47  return_code = e.code
48 
49  #sleep again before checking
50  time.sleep(3)
51 
52  if eostools.fileExists(dest) and eostools.isFile(dest):
53  if source.size() == destination.size():
54  return_code = 0
55  break
56 
57  sys.exit(return_code)
def isDirectory(path)
Definition: eostools.py:261
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def fileExists(path)
Definition: eostools.py:198
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def setCAFPath()
Definition: eostools.py:14
Definition: main.py:1
def isFile(path)
Definition: eostools.py:274
#define str(s)