Skip to content

Commit

Permalink
[scheduler] Fix possible failure during first object task launch
Browse files Browse the repository at this point in the history
This issue may happen during the first task launch on an object when some other tasks are also running on this object.
We have then following node.scheduler.log:
 failed run '%s' exit code:1"

This patch fix following silent stack

    Traceback (most recent call last):
      File /usr/lib/python3.8/runpy.py, line 194, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File /usr/lib/python3.8/runpy.py, line 87, in _run_code
        exec(code, run_globals)
      File /usr/share/opensvc/opensvc/__main__.py, line 131, in <module>
        ret = main(sys.argv)
      File /usr/share/opensvc/opensvc/__main__.py, line 74, in main
        ret = Mgr()(argv=argv[2:])
      File /usr/share/opensvc/opensvc/commands/mgr/__init__.py, line 357, in __call__
        ret = self._main(argv=argv)
      File /usr/share/opensvc/opensvc/commands/mgr/__init__.py, line 331, in _main
        ret = self.do_svcs_action(options, action, argv=argv)
      File /usr/share/opensvc/opensvc/commands/mgr/__init__.py, line 137, in do_svcs_action
        ret = self.node.do_svcs_action(action, options)
      File /usr/share/opensvc/opensvc/core/node/node.py, line 2452, in do_svcs_action
        data, err, errs = self.do_svcs_action_sequential(action, options, svcs, need_aggregate)
      File /usr/share/opensvc/opensvc/core/node/node.py, line 2491, in do_svcs_action_sequential
        ret = svc.action(action, options)
      File /usr/share/opensvc/opensvc/core/objects/svc.py, line 925, in action
        return self._action(action, options=options)
      File /usr/share/opensvc/opensvc/core/scheduler.py, line 166, in _func
        self.sched.action_timestamps(action, options.rid)
      File /usr/share/opensvc/opensvc/core/scheduler.py, line 1053, in action_timestamps
        timestamp(tsfile, last=last)
      File /usr/share/opensvc/opensvc/core/scheduler.py, line 150, in timestamp
        os.makedirs(timestamp_d, 0o755)
      File /usr/lib/python3.8/os.py, line 223, in makedirs
        mkdir(name, mode)
    FileExistsError: [Errno 17] File exists: '/var/lib/opensvc/svc/<svcname>/scheduler'
  • Loading branch information
cgalibern committed Dec 9, 2021
1 parent 279ee94 commit 7a8c36d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions opensvc/core/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,20 @@ def timestamp(timestamp_f, last=None):
last = time.time()
elif type(last) == datetime.datetime:
last = to_time(last)
timestamp_d = os.path.dirname(timestamp_f)
if not os.path.isdir(timestamp_d):
os.makedirs(timestamp_d, 0o755)
buff = repr(last)
with open(timestamp_f, 'w') as ofile:
ofile.write(buff+os.linesep)
try:
with open(timestamp_f, 'w') as ofile:
ofile.write(buff+os.linesep)
except (OSError, IOError):
timestamp_d = os.path.dirname(timestamp_f)
try:
os.makedirs(timestamp_d, 0o755)
except (OSError, IOError):
# another // call may have created this dir
# ignore error, and try again write file
pass
with open(timestamp_f, 'w') as ofile:
ofile.write(buff+os.linesep)


def sched_action(func):
Expand Down

0 comments on commit 7a8c36d

Please sign in to comment.