Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add schedule debug command #223

Merged
merged 5 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <aud> - 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.\n" +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be helpful to say what resetting is, ie "Resets the scheduler, clearing completed tasks."

"</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) !== null;
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} ${hasRoomIndicator}</b> (<code>${task.id}</code>) ${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);
}
}
Loading