Skip to content

Commit

Permalink
clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
linweihs committed Oct 30, 2024
1 parent ed01119 commit 6bfb281
Showing 1 changed file with 2 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.hadoop.fs.FileStatus;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Duration;


/**
Expand All @@ -43,20 +42,7 @@ public TimeBasedSnapshotCleanupPolicy(Properties props) {
@Override
public boolean shouldDeleteSnapshot(FileStatus snapshot, Trash trash) {
DateTime snapshotTime = Trash.TRASH_SNAPSHOT_NAME_FORMATTER.parseDateTime(snapshot.getPath().getName());
System.out.println("Parsed time is " + snapshotTime + " and the timezone is " + snapshotTime.getZone());
System.out.println("Target clean up time is " + snapshotTime.plusMinutes(this.retentionMinutes));
System.out.println("Current time is " + new DateTime() + " and the timezone is " + new DateTime().getZone());

DateTime now = new DateTime().withZone(DateTimeZone.UTC).minusHours(7); // mimic the time in azkaban
DateTime targetCleanupTime = snapshotTime.plusMinutes(this.retentionMinutes);
DateTime delta = targetCleanupTime.minus(now.getMillis());

Duration duration = new Duration(now, targetCleanupTime);
duration.toStandardHours();
duration.toStandardMinutes();
System.out.println("Time delta is " + duration.toStandardHours() + " hours and " + duration.toStandardMinutes() + " minutes");


return snapshotTime.plusMinutes(this.retentionMinutes).isBeforeNow();
// To ensure that the comparison between snapshotTime and the current time is done in the same time zone
return snapshotTime.plusMinutes(this.retentionMinutes).isBefore(DateTime.now(DateTimeZone.UTC));
}
}

0 comments on commit 6bfb281

Please sign in to comment.