-
-
Notifications
You must be signed in to change notification settings - Fork 604
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
Queue #1592
Comments
hey, @edneijunior I got your email and was working on a long term solution today. The solution I came up with was to implement an optional queue on listener ( Here is an example of the upcoming changes: In the above example, 1 message will be processed every 10 seconds via Here is the corresponding console output from the above example: This p-queue implementation will be unopinionated, meaning you will HAVE TO provide the p-queue options object as the second parameter in order to use the p-queue at all. This is because those options will be subjective to the desired behaviour of your automation and your desired throughput. Hopefully, this will satisfy your needs for a p-queue. Please let me know if there are any other considerations. Thanks |
@github-actions run ⚡ Release! ⚡(async () => {
function exec(cmd) {
console.log(execSync(cmd).toString());
}
// Config
const gitUserEmail = "github-actions[bot]@users.noreply.github.com";
const gitUserName = "github-actions[bot]";
exec(`echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc`);
exec(`git config --global user.email "${gitUserEmail}"`);
exec(`git config --global user.name "${gitUserName}"`);
exec(`npm i -D`);
exec(`npm run release-ci minor`);
//comment on the issue
var result = execSync(`npx auto-changelog -o ./tempchangelog.txt --commit-limit false --template ./compact-keepachangelog.hbs --stdout`).toString();
await postComment(result);
//create changelog image
exec(`npm run release-image`);
exec(`git commit -a -m 'updated release-image'`);
exec(`git push --force`);
})(); |
Changelog🚀 Release 3.11.0 (2021-04-17)
|
@edneijunior if you share your desired pqueue behaviour I can reply with the code that will work in the latest version of the library |
... what about outgoing messages when they're not sent in response to incoming messages? 🤔 |
@lesmo for those you can implement a PQueue manually |
Bro, you are awesome. |
WA Version 3.11.1 CLIENT.onMessage(message => {
if (message.quotedMsgObj && message.quotedMsgObj.mimetype) {
let m = message.quotedMsgObj;
const mediaData = openWA.decryptMedia(m, uaOverride).then(function (DECRYPTED_DATA) {
var filename = `${message.t}.${mime.extension(m.mimetype)}`;
fs.writeFile('/var/www/w2api/public/cdn/' + filename, Buffer.from(DECRYPTED_DATA, 'base64'), 'base64', function (err) {
if (err) {
console.log("#Error on saving file");
m['body'] = `data:${m.mimetype};base64,${m['body']}`;
m['filelink'] = 'cdn/' + filename;
that.PROCESS_MESSAGE(message);
} else {
m['body'] = `data:${m.mimetype};base64,${base64Encode('/var/www/w2api/public/cdn/' + filename)}`;
m['filelink'] = 'cdn/' + filename;
that.PROCESS_MESSAGE(message);
}
});
});
} else if (message.mimetype) {
const mediaData = openWA.decryptMedia(message, uaOverride).then(function (DECRYPTED_DATA) {
var filename = `${message.t}.${mime.extension(message.mimetype)}`;
fs.writeFile('/var/www/w2api/public/cdn/' + filename, Buffer.from(DECRYPTED_DATA, 'base64'), 'base64', function (err) {
if (err) {
console.log("#Error on saving file");
message['body'] = `data:${message.mimetype};base64,${message['body']}`;
message['filelink'] = 'cdn/' + filename;
that.PROCESS_MESSAGE(message);
} else {
message['body'] = `data:${message.mimetype};base64,${base64Encode('/var/www/w2api/public/cdn/' + filename)}`;
message['filelink'] = 'cdn/' + filename;
that.PROCESS_MESSAGE(message);
}
});
});
} else {
that.PROCESS_MESSAGE(message);
}
},{
interval:10000,
concurrency: 1,
intervalCap:1
});
``` |
I would like to send messages following the best practices. I want to send messages without overloading the session. |
can you explain what's going on here and what is your question? Regarding setting up to follow best practices, you should implement a setup that works for your use case. If you're not getting that many incoming messages then maybe you don't need to implement a queue. Based on community discussions, people get away with high message throughput without any issues. The example provided is a bit extreme (1 message every 10 seconds) so I'll give you a starting point that should be safe but also not cause a huge backlog of queued messages:
{
interval: 5000,
intervalCap: 10,
concurrency: 2,
carryoverConcurrencyCount: true //<=== important to set this to true so you don't miss messages!
}
{
interval: 2000,
intervalCap: 5,
concurrency: 1,
carryoverConcurrencyCount: true
}
{
interval: 1000,
intervalCap: 1,
concurrency: 1,
carryoverConcurrencyCount: true
} if you have any more discussion around p-queue, please join the discord (click the badge in the readme) and ask in the #pq channel thanks |
Describe the bug
it is not a bug, but a cry for help!
create() code
Expected behavior
an implemented queue
The text was updated successfully, but these errors were encountered: