18 from typing
import Callable, List
23 from .remote
import processRemote
24 from .current_task_run
import setCurrentTaskRun
25 from .._folder_manager
import folder_manager
26 from ..entities
import TaskRun, TaskRunStatus
27 from ..logging
import createFormatter, initializeLogger
28 from ..logging.severity
import LogSeverity
29 from ..networking
import RequestFailedError
32 def _initializeLogger(taskRun: TaskRun) ->
None:
34 severity = LogSeverity.info
35 verbose = taskRun.parameters.get(
"verbose",
False)
38 severity = LogSeverity.debug
40 streamHandler = logging.StreamHandler(sys.stdout)
41 streamHandler.setLevel(severity.getLevel())
42 streamHandler.setFormatter(createFormatter(
49 logPath = folder_manager.getRunLogsDir(taskRun.id) /
"run.log"
50 initializeLogger(severity, logPath, streamHandler)
53 def _prepareForExecution(taskRun: TaskRun) ->
None:
54 _initializeLogger(taskRun)
57 status = TaskRunStatus.inProgress,
58 message =
"Executing task."
62 def initializeRTask(mainFunction: Callable[[TaskRun],
None], args: List[str]) ->
None:
64 Initializes and starts the R task as Coretex TaskRun
68 mainFunction : Callable[[ExecutingTaskRun], None]
70 args : Optional[List[str]]
71 list of command line arguments
74 taskRun, callback = processRemote(args)
77 _prepareForExecution(taskRun)
78 setCurrentTaskRun(taskRun)
82 logging.getLogger(
"coretexpylib").info(
"TaskRun execution started")
86 except RequestFailedError:
87 callback.onNetworkConnectionLost()
88 except KeyboardInterrupt:
89 callback.onKeyboardInterrupt()
90 except BaseException
as ex:
91 callback.onException(ex)