Skip to content

Commit

Permalink
#1906 dont kill terminated instances
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Feb 28, 2024
1 parent 243750b commit 439c395
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/java/com/rultor/agents/aws/PrunesInstances.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,25 @@ public void execute(final Talks talks) throws IOException {
final Collection<String> seen = new LinkedList<>();
for (final Reservation rsrv : res.getReservations()) {
final Instance instance = rsrv.getInstances().get(0);
final String status = this.api.aws().describeInstanceStatus(
new DescribeInstanceStatusRequest()
.withIncludeAllInstances(true)
.withInstanceIds(instance.getInstanceId())
).getInstanceStatuses().get(0).getInstanceState().getName();
final String label = String.format(
"%s/%s/%s",
instance.getInstanceId(),
instance.getInstanceType(),
this.api.aws().describeInstanceStatus(
new DescribeInstanceStatusRequest()
.withIncludeAllInstances(true)
.withInstanceIds(instance.getInstanceId())
).getInstanceStatuses().get(0).getInstanceState().getName()
status
);
seen.add(label);
final Date time = instance.getLaunchTime();
if (time.getTime() > threshold) {
continue;
}
if ("terminated".equals(status)) {
continue;
}
this.api.aws().terminateInstances(
new TerminateInstancesRequest()
.withInstanceIds(instance.getInstanceId())
Expand Down

0 comments on commit 439c395

Please sign in to comment.