Search code examples
artificial-intelligencedasha

How can I multithread dasha.ai queue for calling some users simultaneously?


Is it possible to call some users simultaneously in dasha.ai? Maximum count of simultaneous calls and how can I implement that


Solution

  • Simultaneous calls already implemented via Conversation Queue

    Simultaneous calls limits

    1. Instance limit
      Instance limit is set by you in sdk application.
      It must be initialized through parameter concurrency in application.start method (default value - 1)

       await application.start({ concurrency: 10 });
      
    2. Group limit
      All users have a Default group which does not have a limit (theoretically infinite)
      However if you are using a custom group - you should set max-concurrency to a number of simultaneous calls in it
      You can set and update max-concurrency via dasha cli
      Example for creating group

       dasha group create group_name --max-concurrency=50  
      

      and updating group

       dasha group update group_name --max-concurrency=50  
      

      Which group will be used by your application (instance) is defined by deploy method:

       dasha.deploy("app", { groupName: "Default" }); 
      
    3. Customer limit
      This limit can be changed only on demand (you can't manually change it, atleast for now)

    Application

    You need to specify how to handle calls via Conversation Queue: for calls that can be started you must specify ready event

    application.queue.on("ready", async (key, conversation) => {
      conversation.input = getInput(key); // getInput must return an object that consist of input variables for a call 
      const result = await conversation.execute();  // start conversation/call
    });
    

    This event will be started for each call asynchronously

    To make simultaneous calls - push as many calls as you need into a queue (example for adding one call into queue, that must be started within one hour or it will be timed out):

    application.queue.push("some_unique_key", {
        after: new Date(Date.now()),
        before: new Date(Date.now() + 60 * 60 * 1000)
    });
    

    While you have free limits and calls in queue that ready to start - they will be processed as soon as possible