(scheduleId: string)
| 37 | }; |
| 38 | |
| 39 | export const runCommand = async (scheduleId: string) => { |
| 40 | const { |
| 41 | application, |
| 42 | command, |
| 43 | shellType, |
| 44 | scheduleType, |
| 45 | compose, |
| 46 | serviceName, |
| 47 | appName, |
| 48 | serverId, |
| 49 | } = await findScheduleById(scheduleId); |
| 50 | |
| 51 | const deployment = await createDeploymentSchedule({ |
| 52 | scheduleId, |
| 53 | title: "Schedule", |
| 54 | description: "Schedule", |
| 55 | }); |
| 56 | |
| 57 | if (scheduleType === "application" || scheduleType === "compose") { |
| 58 | let containerId = ""; |
| 59 | let serverId = ""; |
| 60 | if (scheduleType === "application" && application) { |
| 61 | const container = await getServiceContainer( |
| 62 | application.appName, |
| 63 | application.serverId, |
| 64 | ); |
| 65 | containerId = container?.Id || ""; |
| 66 | serverId = application.serverId || ""; |
| 67 | } |
| 68 | if (scheduleType === "compose" && compose) { |
| 69 | const container = await getComposeContainer(compose, serviceName || ""); |
| 70 | containerId = container?.Id || ""; |
| 71 | serverId = compose.serverId || ""; |
| 72 | } |
| 73 | |
| 74 | if (serverId) { |
| 75 | try { |
| 76 | await execAsyncRemote( |
| 77 | serverId, |
| 78 | ` |
| 79 | set -e |
| 80 | echo "Running command: docker exec ${containerId} ${shellType} -c '${command}'" >> ${deployment.logPath}; |
| 81 | docker exec ${containerId} ${shellType} -c '${command}' >> ${deployment.logPath} 2>> ${deployment.logPath} || { |
| 82 | echo "❌ Command failed" >> ${deployment.logPath}; |
| 83 | exit 1; |
| 84 | } |
| 85 | echo "✅ Command executed successfully" >> ${deployment.logPath}; |
| 86 | `, |
| 87 | ); |
| 88 | } catch (error) { |
| 89 | await updateDeploymentStatus(deployment.deploymentId, "error"); |
| 90 | throw error; |
| 91 | } |
| 92 | } else { |
| 93 | const writeStream = createWriteStream(deployment.logPath, { flags: "a" }); |
| 94 | |
| 95 | try { |
| 96 | if (IS_CLOUD) { |
no test coverage detected