Skip to content

Commit 26b02b5

Browse files
Add schedule debug command (#223)
* ScheduleCommand: extract printUpcomingTasks * ScheduleCommand: add `debug` subcommand that also shows completed task IDs * Document status, refresh, schedule view, schedule debug, schedule reset commands in help command * Add more info to reset command --------- Co-authored-by: Will Hunt <[email protected]>
1 parent a880e81 commit 26b02b5

File tree

3 files changed

+59
-19
lines changed

3 files changed

+59
-19
lines changed

src/Scheduler.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ export class Scheduler {
185185
return Object.values(this.pending);
186186
}
187187

188+
/**
189+
* Return a list of completed task IDs.
190+
*/
191+
public inspectCompleted(): string[] {
192+
// slice() is just to clone the array to prevent mutations
193+
return this.completedIds.slice();
194+
}
195+
188196
private async persistProgress() {
189197
const completedIds = this.completedIds.slice().reverse().slice(0, KEEP_LAST_TASKS).reverse();
190198
await this.client.setAccountData(ACD_SCHEDULER, {

src/commands/HelpCommand.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export class HelpCommand implements ICommand {
4242
"!conference run &lt;aud&gt; - Runs the schedule in the given auditorium. If 'all' is used,\n" +
4343
" then all auditoriums will be run.\n" +
4444
"!conference stop - Halts all scheduling, resetting the bot back to no watched auditoriums.\n" +
45+
"!conference status|refresh - Refreshes the schedule source and then displays the status of the conference. MAY NOT REFRESH THE SCHEDULER, BEWARE.\n" +
46+
"!conference schedule view - Shows upcoming scheduler tasks.\n" +
47+
"!conference schedule debug - Shows upcoming scheduler tasks as well as a list of stored completed task IDs.\n" +
48+
"!conference schedule reset - Resets the scheduler which will clear all completed tasks. Some tasks may run again.\n" +
4549
"</code></pre>" +
4650
"<h4>People management:</h4>" +
4751
"<pre><code>" +

src/commands/ScheduleCommand.ts

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,58 @@ export class ScheduleCommand implements ICommand {
3030
await this.scheduler.reset();
3131
await this.client.sendNotice(roomId, "Schedule processing has been reset.");
3232
} else if (args[0] === 'view') {
33-
const upcoming = sortTasks(this.scheduler.inspect());
34-
let html = "Upcoming tasks:<ul>";
35-
for (const task of upcoming) {
36-
const hasTalkRoom = this.conference.getTalk(task.talk.id) !== undefined;
37-
const taskStart = moment(getStartTime(task));
38-
const formattedTimestamp = taskStart.format("YYYY-MM-DD HH:mm:ss [UTC]ZZ");
39-
40-
if (html.length > 20000) {
41-
// chunk up the message so we don't fail to send one very large event.
42-
html += "</ul>";
43-
await this.client.sendHtmlNotice(roomId, html);
44-
html = "…<ul>";
45-
}
46-
47-
const hasRoomIndicator = hasTalkRoom ? 'has talk room' : 'no talk room';
48-
html += `<li>${formattedTimestamp}: <b>${task.type} on ${task.talk.title}</b> (<code>${task.id}</code>, ${hasRoomIndicator}) ${taskStart.fromNow()}</li>`;
49-
}
50-
html += "</ul>";
51-
await this.client.sendHtmlNotice(roomId, html);
33+
await this.printUpcomingTasks(roomId);
34+
} else if (args[0] === 'debug') {
35+
await this.printUpcomingTasks(roomId);
36+
await this.printCompletedTasks(roomId);
5237
} else if (args[0] === 'execute') {
5338
await this.scheduler.execute(args[1]);
5439
await this.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');
5540
} else {
5641
await this.client.sendNotice(roomId, "Unknown schedule command.");
5742
}
5843
}
44+
45+
private async printUpcomingTasks(roomId: string) {
46+
const upcoming = sortTasks(this.scheduler.inspect());
47+
let html = "Upcoming tasks:<ul>";
48+
for (const task of upcoming) {
49+
const hasTalkRoom = this.conference.getTalk(task.talk.id) !== undefined;
50+
const taskStart = moment(getStartTime(task));
51+
const formattedTimestamp = taskStart.format("YYYY-MM-DD HH:mm:ss [UTC]ZZ");
52+
53+
if (html.length > 20000) {
54+
// chunk up the message so we don't fail to send one very large event.
55+
html += "</ul>";
56+
await this.client.sendHtmlNotice(roomId, html);
57+
html = "…<ul>";
58+
}
59+
60+
const hasRoomIndicator = hasTalkRoom ? 'has talk room' : 'no talk room';
61+
html += `<li>${formattedTimestamp}: <b>${task.type} on ${task.talk.title}</b> (<code>${task.id}</code>, ${hasRoomIndicator}) ${taskStart.fromNow()}</li>`;
62+
}
63+
html += "</ul>";
64+
await this.client.sendHtmlNotice(roomId, html);
65+
}
66+
67+
private async printCompletedTasks(roomId: string) {
68+
const completed = this.scheduler.inspectCompleted();
69+
let html = "Completed tasks:<ul>";
70+
completed.sort();
71+
72+
for (const taskId of completed) {
73+
if (html.length > 20000) {
74+
// chunk up the message so we don't fail to send one very large event.
75+
html += "</ul>";
76+
await this.client.sendHtmlNotice(roomId, html);
77+
html = "…<ul>";
78+
}
79+
80+
html += `<li>${taskId}</li>`;
81+
}
82+
83+
html += "</ul>";
84+
85+
await this.client.sendHtmlNotice(roomId, html);
86+
}
5987
}

0 commit comments

Comments
 (0)