orders: Fix manager not processing immediately (#1193)

* orders: Fix manager not processing immediately

This ensures that orders are processed as soon as orderManager claims to have started.

Specifically this will fix an eager call to CancelAllOrders not finding
anything until after the first Interval run.

* orders: Fix reset timer call

This fix is small niggle.
The existing code was more complicated than it needed to be, whilst also
ignoring the return of timer.Reset and the conditional need to drain the
channel. It's unlikely but possible during transient resource
starvation.

* OrderManager: Simplify startup process

This simplifies the sequence and Adds to the wg first.
We won't bail from the run() during any type of processOrders, and
that's something we can fix later
This commit is contained in:
Gareth Kirwan
2023-06-09 02:39:07 +01:00
committed by GitHub
parent c8537c47a2
commit 466327cdaa
2 changed files with 3 additions and 7 deletions

View File

@@ -108,21 +108,17 @@ func (m *OrderManager) gracefulShutdown() {
// run will periodically process orders
func (m *OrderManager) run() {
log.Debugln(log.OrderMgr, "Order manager started.")
timer := time.NewTimer(orderManagerDelay)
m.processOrders()
for {
select {
case <-m.shutdown:
m.gracefulShutdown()
if !timer.Stop() {
<-timer.C
}
m.orderStore.wg.Done()
log.Debugln(log.OrderMgr, "Order manager shutdown.")
return
case <-timer.C:
case <-time.After(orderManagerInterval):
// Process orders go routine allows shutdown procedures to continue
go m.processOrders()
timer.Reset(orderManagerDelay)
}
}
}

View File

@@ -24,7 +24,7 @@ var (
errNilCommunicationsManager = errors.New("cannot start with nil communications manager")
errNilOrder = errors.New("nil order received")
errFuturesTrackingDisabled = errors.New("tracking futures positions disabled. enable it via config under orderManager activelyTrackFuturesPositions")
orderManagerDelay = time.Second * 10
orderManagerInterval = time.Second * 10
defaultOrderSeekTime = -time.Hour * 24 * 365
)