You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Send a target list of users a message on a regular time-based cadence using Cron.
My ultimate use-case:
Be able to spin up instances of the framework in a separate Worker Thread that would let me perform operations in multiple threads without having to fully spin up a full bot instance (but maybe this is where integrators come into play....)
My initial approach:
Use the Bree library to spin up a thread to handle the message sending and then teardown again.
I've left my commented code in because it shows the different stuff I tried to get it to work.
Conclusion:
At least as far as I tried, the above approach won't work for the following reasons:
The framework needs to boot up the bot fully in a thread before it can really do anything.
The reason is, from what I read in the framework's code, the bot performs a self-discovery upon boot up during which it re-discovers the rooms it's a member off and populates it's internal properties based on what it finds.
The framework looks to its internal properties to respond to commands like getBotByRoomID().
If the re-discovery phase doesn't populate those internal properties, then getBotByRoomID() returns undefined
If I allow it to fully spin up another bot instance in the other thread, while its running, it could respond to other commands that come in at that same time, resulting in 1+ responses to users.
During teardown, messages / interactions could get "lost" in flight
My eventual solution:
I ended up using Node-cron to solve my particular issue.
In the frameworks initialized event, I run a setup handler. This handler then runs the following code example:
var task = cron.schedule('0 8 * * Fri', ()=>{
import('p-map').then(pMap=>{
var pMap = pMap.default;
let isCancelled = false;
const concurrency = os.cpus().length;
let expected = [];
async function mapper(room){
if( isCancelled ) return;
try{
// run your bot code here
return retVal;
}catch(err){
logger.log({
level: 'error',
message: err
})
}
}
(async ()=>{
let result = await pMap(records, mapper, { concurrency });
})()
})
});
The text was updated successfully, but these errors were encountered:
My initial use-case:
Send a target list of users a message on a regular time-based cadence using Cron.
My ultimate use-case:
Be able to spin up instances of the framework in a separate Worker Thread that would let me perform operations in multiple threads without having to fully spin up a full bot instance (but maybe this is where integrators come into play....)
My initial approach:
Use the Bree library to spin up a thread to handle the message sending and then teardown again.
Initial "job" script: (In the "jobs" directory)
I've left my commented code in because it shows the different stuff I tried to get it to work.
Conclusion:
At least as far as I tried, the above approach won't work for the following reasons:
getBotByRoomID()
.getBotByRoomID()
returnsundefined
My eventual solution:
I ended up using Node-cron to solve my particular issue.
In the frameworks
initialized
event, I run a setup handler. This handler then runs the following code example:The text was updated successfully, but these errors were encountered: