Skip to content

Commit ee7325c

Browse files
authored
Use global timeout on aws, az & gcp (#587)
* Use global timeout on `aws`, `az` & `gcp` * Fix time/duration blunder * Provide a consistent timeout message * Simplify timeout * Report timeout results as failures
1 parent 71b2ad3 commit ee7325c

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

task/common/machine/script.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
func Script(script string, credentials *map[string]string, variables common.Variables, timeout time.Duration) string {
16-
timeoutString := strconv.Itoa(int(timeout / time.Second))
16+
timeoutString := strconv.Itoa(int(time.Now().Add(timeout).Unix()))
1717
if timeout <= 0 {
1818
timeoutString = "infinity"
1919
}
@@ -67,21 +67,27 @@ TPI_MACHINE_IDENTITY="$(uuidgen)"
6767
TPI_LOG_DIRECTORY="$(mktemp --directory)"
6868
TPI_DATA_DIRECTORY="/opt/task/directory"
6969
70+
TPI_START_COMMAND="/bin/bash -lc 'exec /usr/bin/tpi-task'"
71+
TPI_REMAINING_RUN_TIME=$((%s-$(date +%%s)))
72+
if (( TPI_REMAINING_RUN_TIME < 1 )); then
73+
TPI_START_COMMAND="/bin/bash -c 'sleep infinity'"
74+
TPI_REMAINING_RUN_TIME=1
75+
fi
76+
7077
source /opt/task/credentials
7178
7279
sudo tee /etc/systemd/system/tpi-task.service > /dev/null <<END
7380
[Unit]
7481
After=default.target
7582
[Service]
7683
Type=simple
77-
ExecStart=-/bin/bash -lc 'exec /usr/bin/tpi-task'
84+
ExecStart=-$TPI_START_COMMAND
7885
ExecStop=/bin/bash -c 'source /opt/task/credentials; systemctl is-system-running | grep stopping || echo "{\\\\"result\\\\": \\\\"\$SERVICE_RESULT\\\\", \\\\"code\\\\": \\\\"\$EXIT_STATUS\\\\", \\\\"status\\\\": \\\\"\$EXIT_CODE\\\\"}" > "$TPI_LOG_DIRECTORY/status-$TPI_MACHINE_IDENTITY" && RCLONE_CONFIG= rclone copy "$TPI_LOG_DIRECTORY" "\$RCLONE_REMOTE/reports"'
7986
ExecStopPost=/usr/bin/tpi-task-shutdown
8087
Environment=HOME=/root
8188
EnvironmentFile=/opt/task/variables
8289
WorkingDirectory=/opt/task/directory
83-
TimeoutStartSec=%s
84-
TimeoutStopSec=infinity
90+
RuntimeMaxSec=$TPI_REMAINING_RUN_TIME
8591
[Install]
8692
WantedBy=default.target
8793
END

task/common/machine/storage.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ func Status(ctx context.Context, remote string, initialStatus common.Status) (co
101101
} else {
102102
initialStatus[common.StatusCodeFailed] += 1
103103
}
104+
} else if statusReport.Result == "timeout" {
105+
initialStatus[common.StatusCodeFailed] += 1
104106
}
105107
}
106108
return initialStatus, nil

0 commit comments

Comments
 (0)