Open Phoscur opened 7 years ago
You can check something like
const client = new Telegram(...);
if(!client._workers)
{
/* In worker instance */
}
else
{
/* in master instance */
}
but having official client.isMaster
or client.isWorker
would be nice.
Is not that what you are looking for? https://github.com/Naltox/telegram-node-bot#clustering
const tg = new Telegram.Telegram('YOUR_TOKEN', {
workers: 1
})
tg.sendMessage(123, 'test message') //will be sent 2 times (one time on master and one time on worker)
tg.onMaster(() => {
tg.sendMessage(123, 'test message') //will be sent one time
})
Yes @AndryFM, that's what I'm refering to, and it should answer @vsviridov comment.
What I mean is, that this part is this very much undocumented besides that short paragraph. It does not explain
Currently, not reading the refered paragraph will produce weird duplicate messages. The default worker count should be zero, eliminating the need to know about clustering at all.
Looks like a cool feature, but really, generating duplicate messages by default sounds rather like a bug :P Please explain how to use it correctly and use zero as default worker count!