Coder Social home page Coder Social logo

Comments (4)

tomli380576 avatar tomli380576 commented on July 24, 2024

Another temporary fix is to delete the server that BOB is currently in and make a new one.
For development, disable any role creation call if the role is already created.

from yet-another-better-office-hour-bot.

tomli380576 avatar tomli380576 commented on July 24, 2024

The Promise.race() fix is at catch-role-creation-fail branch.

If we need to catch timeout everywhere, here's the decorator solution:

function timeoutable(timeoutAfter: number, errMsg: string) {
    return (_t: unknown,
        _p: string,
        descriptor: PropertyDescriptor) => {
        const promiseToRace = descriptor.value;
        let timeoutHandle: NodeJS.Timeout;

        descriptor.value = function (this: any) {
            return Promise.race([
                // eslint-disable-next-line prefer-rest-params
                promiseToRace?.call(this, arguments),
                new Promise<never>(
                    (_, reject) => {
                        timeoutHandle = setTimeout(() =>
                            reject(new Error(errMsg)),
                            timeoutAfter);
                    }
                ).finally(() => {
                    clearTimeout(timeoutHandle);
                    console.log('timeout cleared');
                })
            ]);
        };
    };
}

Usage:

class SomeClass {

    // force reject after 5 seconds
    @timeoutable(5000, "Method timed out.")
    async methodThatCanTakeForever() {
        // ...
    }
}

from yet-another-better-office-hour-bot.

KaoushikMurugan avatar KaoushikMurugan commented on July 24, 2024

Might be related to this issue, maybe not. But I think the "Ensure roles exist" function itself can be avoided being called unnecessarily every time the bot needs to check if a user has a role. Instead, we should do something similar to how we process the queue messages and store the role id (or object) in an AttendingServer class member and then use that whenever doing a role check. We should only worry about if the roles exist when starting the server and when a role is deleted

edit: also store the role ids in firebase

from yet-another-better-office-hour-bot.

tomli380576 avatar tomli380576 commented on July 24, 2024

The issue doesn't seem to show up any more. I think we can safely ignore it for now

from yet-another-better-office-hour-bot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.