class_docstr: Execute using OAR
  
  The plugin_args input to run can be used to control the OAR execution.
  Currently supported options are:
  
  - template : template to use for batch job submission
  - oarsub_args : arguments to be prepended to the job execution
                  script in the oarsub call
  - max_jobname_len: maximum length of the job name.  Default 15.
class_docstr_tok: ["Execute","using","OAR","The","plugin_args","input","to","run","can","be","used","to","control","the","OAR","execution",".","Currently","supported","options","are",":","-","template",":","template","to","use","for","batch","job","submission","-","oarsub_args",":","arguments","to","be","prepended","to","the","job","execution","script","in","the","oarsub","call","-","max_jobname_len",":","maximum","length","of","the","job","name",".","Default","15","."]
code: def _submit_batchtask(self, scriptfile, node):
      cmd = CommandLine(
          "oarsub",
          environ=dict(os.environ),
          resource_monitor=False,
          terminal_output="allatonce",
      )
      path = os.path.dirname(scriptfile)
      oarsubargs = ""
      if self._oarsub_args:
          oarsubargs = self._oarsub_args
      if "oarsub_args" in node.plugin_args:
          if (
              "overwrite" in node.plugin_args
              and node.plugin_args["overwrite"]
          ):
              oarsubargs = node.plugin_args["oarsub_args"]
          else:
              oarsubargs += " " + node.plugin_args["oarsub_args"]
  
      if node._hierarchy:
          jobname = ".".join(
              (dict(os.environ)["LOGNAME"], node._hierarchy, node._id)
          )
      else:
          jobname = ".".join((dict(os.environ)["LOGNAME"], node._id))
      jobnameitems = jobname.split(".")
      jobnameitems.reverse()
      jobname = ".".join(jobnameitems)
      jobname = jobname[0 : self._max_jobname_len]
  
      if "-O" not in oarsubargs:
          oarsubargs = "{} -O {}".format(
              oarsubargs,
              os.path.join(path, jobname + ".stdout"),
          )
      if "-E" not in oarsubargs:
          oarsubargs = "{} -E {}".format(
              oarsubargs,
              os.path.join(path, jobname + ".stderr"),
          )
      if "-J" not in oarsubargs:
          oarsubargs = "%s -J" % (oarsubargs)
  
      os.chmod(scriptfile, stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
      cmd.inputs.args = f"{oarsubargs} -n {jobname} -S {scriptfile}"
  
      oldlevel = iflogger.level
      iflogger.setLevel(logging.getLevelName("CRITICAL"))
      tries = 0
      while True:
          try:
              result = cmd.run()
          except Exception as e:
              if tries < self._max_tries:
                  tries += 1
                  sleep(self._retry_timeout)
                  # sleep 2 seconds and try again.
              else:
                  iflogger.setLevel(oldlevel)
                  raise RuntimeError(
                      "\n".join(
                          (
                              "Could not submit OAR task for node %s"
                              % node._id,
                              str(e),
                          )
                      )
                  )
          else:
              break
      iflogger.setLevel(oldlevel)
      # retrieve OAR taskid
  
      o = ""
      add = False
      for line in result.runtime.stdout.splitlines():
          if line.strip().startswith("{"):
              add = True
          if add:
              o += line + "\n"
          if line.strip().startswith("}"):
              break
      taskid = json.loads(o)["job_id"]
      self._pending[taskid] = node.output_dir()
      logger.debug(f"submitted OAR task: {taskid} for node {node._id}")
      return taskid
  
file_path: nipype/nipype/pipeline/plugins/oar.py
imports: import os
  import stat
  from time import sleep
  import subprocess
  import simplejson
  from ...None import logging
  from ...interfaces.base import CommandLine
  from .base import SGELikeBatchManagerBase, logger
label_desc: Use image node_id 3 for calling the OARPlugin obj's underlying member method code with example usage: obj._submit_batchtask(scriptfile, node) and returns: taskid