ninjabot icon indicating copy to clipboard operation
ninjabot copied to clipboard

Telegram `/stop` is not working

Open rodrigo-brito opened this issue 2 years ago • 2 comments

Telegram's command /stop is not working. We define the logic here: https://github.com/rodrigo-brito/ninjabot/blob/1a3585bedbaf66ba35e9377635877aa688e5a1e0/order/controller.go#L293-L300

The idea is:

  • The bot will only execute orders when it is in running status. But it is not working.

rodrigo-brito avatar Mar 29 '22 23:03 rodrigo-brito

@rodrigo-brito rough guess, but could it be that the c.finish case is not prioritised over ticker.C?

func (c *Controller) Start() {
	if c.status != StatusRunning {
		c.status = StatusRunning
		go func() {
			ticker := time.NewTicker(c.tickerInterval)
			for {
				select {
				case <-ticker.C:
					c.updateOrders()
				case <-c.finish:
					ticker.Stop()
					return
				}
			}
		}()
		log.Info("Bot started.")
	}
}

ngqinzhe avatar Apr 01 '23 12:04 ngqinzhe

Hi @ngqinzhe, thanks for the suggestion. I don't know. It is inside an infinite loop, if we have the signal of c.finish together with ticker.C, it will run ticker.C, but in the next iteration it will execute c.finish.

It can be replaced by this feature: https://github.com/rodrigo-brito/ninjabot/issues/131 This ticker is a workaround to update pending orders.

rodrigo-brito avatar Apr 01 '23 13:04 rodrigo-brito