18 from typing
import Optional
23 from ..modules
import ui
24 from ..modules.project_utils
import getProject
25 from ..modules.user
import initializeUserSession
26 from ..modules.utils
import onBeforeCommandExecute
27 from ..modules.project_utils
import getProject
28 from ..._folder_manager
import folder_manager
29 from ..._task
import TaskRunWorker, executeRunLocally, readTaskConfig, runLogger
30 from ...configuration
import UserConfiguration
31 from ...entities
import TaskRun, TaskRunStatus
32 from ...resources
import PYTHON_ENTRY_POINT_PATH
33 from ..._task
import TaskRunWorker, executeRunLocally, readTaskConfig, runLogger
36 class RunException(Exception):
41 @click.argument("path", type = click.Path(exists = True, dir_okay = False))
42 @click.option("--name", type = str, default = None)
43 @click.option("--description", type = str, default = None)
44 @click.option("--snapshot", type = bool, default = False)
45 @click.option("--project", "-p", type = str)
46 def run(path: str, name: Optional[str], description: Optional[str], snapshot: bool, project: Optional[str]) ->
None:
47 userConfig = UserConfiguration.load()
49 if userConfig.refreshToken
is None:
50 raise RunException(f
"Failed to execute \"coretex run {path}\" command. Authenticate again using \"coretex login\" command and try again.")
52 parameters = readTaskConfig()
55 folder_manager.clearTempFiles()
57 selectedProject = getProject(project, userConfig)
59 if selectedProject
is None:
64 f
"\n\tName: {selectedProject.name}"
65 f
"\n\tProject type: {selectedProject.projectType.name}"
66 f
"\n\tDescription: {selectedProject.description}"
67 f
"\n\tCreated on: {selectedProject.createdOn}"
70 taskRun: TaskRun = TaskRun.runLocal(
75 [parameter.encode()
for parameter
in parameters],
80 "Task Run successfully started. "
81 f
"You can open it by clicking on this URL {ui.outputUrl(userConfig.frontendUrl, taskRun.entityUrl())}."
83 webbrowser.open(f
"{userConfig.frontendUrl}/{taskRun.entityUrl()}")
85 taskRun.updateStatus(TaskRunStatus.preparingToStart)
87 with TaskRunWorker(userConfig.refreshToken, taskRun.id):
88 runLogger.attach(taskRun.id)
91 "python", str(PYTHON_ENTRY_POINT_PATH),
92 "--taskRunId", str(taskRun.id),
93 "--refreshToken", userConfig.refreshToken
96 returnCode = executeRunLocally(
103 runLogger.flushLogs()
107 runLogger.fatal(f
">> [Coretex] Failed to execute Task. Exit code: {returnCode}")
108 taskRun.updateStatus(TaskRunStatus.completedWithError)
110 taskRun.updateStatus(TaskRunStatus.completedWithSuccess)
112 folder_manager.clearTempFiles()
116 @onBeforeCommandExecute(initializeUserSession)
121 task.add_command(run,
"run")