Skip to content

Commit fcc670b

Browse files
committed
handling error in pipeline
1 parent ddee8d5 commit fcc670b

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadAutoArchiver.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@
2424
import java.util.Optional;
2525
import java.util.concurrent.TimeUnit;
2626
import java.util.function.Function;
27-
import java.util.function.Supplier;
2827

2928
/**
3029
* Routine, which periodically checks all help threads and archives them if there has not been any
3130
* recent activity.
3231
*/
3332
public final class HelpThreadAutoArchiver implements Routine {
3433
private static final Logger logger = LoggerFactory.getLogger(HelpThreadAutoArchiver.class);
35-
private static final int SCHEDULE_MINUTES = 60;
36-
private static final Duration ARCHIVE_AFTER_INACTIVITY_OF = Duration.ofHours(12);
34+
private static final int SCHEDULE_MINUTES = 6;
35+
private static final Duration ARCHIVE_AFTER_INACTIVITY_OF = Duration.ofSeconds(60);
3736

3837
private final HelpSystemHelper helper;
3938

@@ -48,7 +47,7 @@ public HelpThreadAutoArchiver(HelpSystemHelper helper) {
4847

4948
@Override
5049
public Schedule createSchedule() {
51-
return new Schedule(ScheduleMode.FIXED_RATE, 0, SCHEDULE_MINUTES, TimeUnit.MINUTES);
50+
return new Schedule(ScheduleMode.FIXED_RATE, 0, SCHEDULE_MINUTES, TimeUnit.SECONDS);
5251
}
5352

5453
@Override
@@ -128,18 +127,6 @@ private static boolean shouldBeArchived(MessageChannel channel, Instant archiveA
128127

129128
private void handleArchiveFlow(ThreadChannel threadChannel, MessageEmbed embed) {
130129

131-
Supplier<RestAction<Void>> archiveThread =
132-
() -> threadChannel.getManager().setArchived(true);
133-
134-
Function<Throwable, RestAction<Void>> handleFailure = error -> {
135-
if (error instanceof ErrorResponseException) {
136-
logger.warn(
137-
"Unknown error occurred during help thread auto archive routine, archiving thread",
138-
error);
139-
}
140-
return archiveThread.get();
141-
};
142-
143130
Function<Result<Member>, RestAction<Message>> sendEmbedWithMention =
144131
member -> threadChannel.sendMessage(member.get().getAsMention()).addEmbeds(embed);
145132

@@ -159,11 +146,12 @@ private void handleArchiveFlow(ThreadChannel threadChannel, MessageEmbed embed)
159146
})
160147
.mapToResult()
161148
.flatMap(sentEmbed -> {
162-
if (sentEmbed.isSuccess()) {
163-
return archiveThread.get();
149+
if (sentEmbed.getFailure() instanceof ErrorResponseException) {
150+
logger.warn(
151+
"Unknown error occurred during help thread auto archive routine, archiving thread",
152+
sentEmbed.getFailure());
164153
}
165-
166-
return handleFailure.apply(sentEmbed.getFailure());
154+
return threadChannel.getManager().setArchived(true);
167155
})
168156
.queue();
169157
}

0 commit comments

Comments
 (0)