From 6f4b30ca9195585d08c710d09d35f081801c7ed6 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Wed, 28 Feb 2024 09:47:16 +0300 Subject: [PATCH] #1908 show hours --- .../java/com/rultor/agents/aws/PrunesInstances.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/rultor/agents/aws/PrunesInstances.java b/src/main/java/com/rultor/agents/aws/PrunesInstances.java index c1bafa2330..783807e2a7 100644 --- a/src/main/java/com/rultor/agents/aws/PrunesInstances.java +++ b/src/main/java/com/rultor/agents/aws/PrunesInstances.java @@ -75,7 +75,6 @@ public void execute(final Talks talks) throws IOException { new DescribeInstancesRequest() .withFilters(new Filter().withName("tag:rultor").withValues("yes")) ); - final long threshold = new Date().getTime() - TimeUnit.HOURS.toMillis(6L); final Collection seen = new LinkedList<>(); for (final Reservation rsrv : res.getReservations()) { final Instance instance = rsrv.getInstances().get(0); @@ -84,15 +83,17 @@ public void execute(final Talks talks) throws IOException { .withIncludeAllInstances(true) .withInstanceIds(instance.getInstanceId()) ).getInstanceStatuses().get(0).getInstanceState().getName(); + final double hours = + (double) (new Date().getTime() - instance.getLaunchTime().getTime()) + / TimeUnit.HOURS.toMillis(1L); final String label = String.format( - "%s/%s/%s", + "%s/%s/%s/%.2fh", instance.getInstanceId(), instance.getInstanceType(), - status + status, hours ); seen.add(label); - final Date time = instance.getLaunchTime(); - if (time.getTime() > threshold) { + if (hours < 8.0d) { continue; } if ("terminated".equals(status)) {