Refactor backup and command execution utilities for improved robustness

- Removed unnecessary console logging in the backup scheduling utility to streamline output.
- Updated container ID retrieval to handle potential null values gracefully, enhancing error handling.
- Modified command execution logging to use single quotes for consistency and improved readability.
This commit is contained in:
Mauricio Siu
2025-05-04 03:42:55 -06:00
parent 96b1df2199
commit d6f5f6e6cb
2 changed files with 5 additions and 8 deletions
+5 -5
View File
@@ -49,12 +49,12 @@ export const runCommand = async (scheduleId: string) => {
application.appName,
application.serverId,
);
containerId = container.Id;
containerId = container?.Id || "";
serverId = application.serverId || "";
}
if (scheduleType === "compose" && compose) {
const container = await getComposeContainer(compose, serviceName || "");
containerId = container.Id;
containerId = container?.Id || "";
serverId = compose.serverId || "";
}
@@ -64,8 +64,8 @@ export const runCommand = async (scheduleId: string) => {
serverId,
`
set -e
echo "Running command: docker exec ${containerId} ${shellType} -c \"${command}\"" >> ${deployment.logPath};
docker exec ${containerId} ${shellType} -c "${command}" >> ${deployment.logPath} 2>> ${deployment.logPath} || {
echo "Running command: docker exec ${containerId} ${shellType} -c '${command}'" >> ${deployment.logPath};
docker exec ${containerId} ${shellType} -c '${command}' >> ${deployment.logPath} 2>> ${deployment.logPath} || {
echo "❌ Command failed" >> ${deployment.logPath};
exit 1;
}
@@ -81,7 +81,7 @@ export const runCommand = async (scheduleId: string) => {
try {
writeStream.write(
`docker exec ${containerId} ${shellType} -c "${command}"\n`,
`docker exec ${containerId} ${shellType} -c ${command}\n`,
);
await spawnAsync(
"docker",