Skip to content

Commit

Permalink
Add schedule debug command (#223)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
reivilibre and Half-Shot authored Feb 2, 2024
1 parent a880e81 commit 26b02b5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 19 deletions.
8 changes: 8 additions & 0 deletions src/Scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ export class Scheduler {
return Object.values(this.pending);
}

/**
* Return a list of completed task IDs.
*/
public inspectCompleted(): string[] {
// slice() is just to clone the array to prevent mutations
return this.completedIds.slice();
}

private async persistProgress() {
const completedIds = this.completedIds.slice().reverse().slice(0, KEEP_LAST_TASKS).reverse();
await this.client.setAccountData(ACD_SCHEDULER, {
Expand Down
4 changes: 4 additions & 0 deletions src/commands/HelpCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export class HelpCommand implements ICommand {
"!conference run &lt;aud&gt; - Runs the schedule in the given auditorium. If 'all' is used,\n" +
" then all auditoriums will be run.\n" +
"!conference stop - Halts all scheduling, resetting the bot back to no watched auditoriums.\n" +
"!conference status|refresh - Refreshes the schedule source and then displays the status of the conference. MAY NOT REFRESH THE SCHEDULER, BEWARE.\n" +
"!conference schedule view - Shows upcoming scheduler tasks.\n" +
"!conference schedule debug - Shows upcoming scheduler tasks as well as a list of stored completed task IDs.\n" +
"!conference schedule reset - Resets the scheduler which will clear all completed tasks. Some tasks may run again.\n" +
"</code></pre>" +
"<h4>People management:</h4>" +
"<pre><code>" +
Expand Down
66 changes: 47 additions & 19 deletions src/commands/ScheduleCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,58 @@ export class ScheduleCommand implements ICommand {
await this.scheduler.reset();
await this.client.sendNotice(roomId, "Schedule processing has been reset.");
} else if (args[0] === 'view') {
const upcoming = sortTasks(this.scheduler.inspect());
let html = "Upcoming tasks:<ul>";
for (const task of upcoming) {
const hasTalkRoom = this.conference.getTalk(task.talk.id) !== undefined;
const taskStart = moment(getStartTime(task));
const formattedTimestamp = taskStart.format("YYYY-MM-DD HH:mm:ss [UTC]ZZ");

if (html.length > 20000) {
// chunk up the message so we don't fail to send one very large event.
html += "</ul>";
await this.client.sendHtmlNotice(roomId, html);
html = "…<ul>";
}

const hasRoomIndicator = hasTalkRoom ? 'has talk room' : 'no talk room';
html += `<li>${formattedTimestamp}: <b>${task.type} on ${task.talk.title}</b> (<code>${task.id}</code>, ${hasRoomIndicator}) ${taskStart.fromNow()}</li>`;
}
html += "</ul>";
await this.client.sendHtmlNotice(roomId, html);
await this.printUpcomingTasks(roomId);
} else if (args[0] === 'debug') {
await this.printUpcomingTasks(roomId);
await this.printCompletedTasks(roomId);
} else if (args[0] === 'execute') {
await this.scheduler.execute(args[1]);
await this.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅');
} else {
await this.client.sendNotice(roomId, "Unknown schedule command.");
}
}

private async printUpcomingTasks(roomId: string) {
const upcoming = sortTasks(this.scheduler.inspect());
let html = "Upcoming tasks:<ul>";
for (const task of upcoming) {
const hasTalkRoom = this.conference.getTalk(task.talk.id) !== undefined;
const taskStart = moment(getStartTime(task));
const formattedTimestamp = taskStart.format("YYYY-MM-DD HH:mm:ss [UTC]ZZ");

if (html.length > 20000) {
// chunk up the message so we don't fail to send one very large event.
html += "</ul>";
await this.client.sendHtmlNotice(roomId, html);
html = "…<ul>";
}

const hasRoomIndicator = hasTalkRoom ? 'has talk room' : 'no talk room';
html += `<li>${formattedTimestamp}: <b>${task.type} on ${task.talk.title}</b> (<code>${task.id}</code>, ${hasRoomIndicator}) ${taskStart.fromNow()}</li>`;
}
html += "</ul>";
await this.client.sendHtmlNotice(roomId, html);
}

private async printCompletedTasks(roomId: string) {
const completed = this.scheduler.inspectCompleted();
let html = "Completed tasks:<ul>";
completed.sort();

for (const taskId of completed) {
if (html.length > 20000) {
// chunk up the message so we don't fail to send one very large event.
html += "</ul>";
await this.client.sendHtmlNotice(roomId, html);
html = "…<ul>";
}

html += `<li>${taskId}</li>`;
}

html += "</ul>";

await this.client.sendHtmlNotice(roomId, html);
}
}

0 comments on commit 26b02b5

Please sign in to comment.