telegram-node-bot icon indicating copy to clipboard operation
telegram-node-bot copied to clipboard

Clustering

Open Phoscur opened this issue 8 years ago • 3 comments

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!

Phoscur avatar Jan 19 '17 17:01 Phoscur

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.

vsviridov avatar Feb 04 '17 08:02 vsviridov

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
})

AndryFM avatar Feb 06 '17 19:02 AndryFM

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

  • How to actually execute a task (algorithmic work) on worker and then send messages only with master
  • How to disable workers

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.

Phoscur avatar Feb 06 '17 19:02 Phoscur