Implement graceful shutdown of agent.DataAccess (#1008)

* Implements graceful shutdown of agent.DataAccess and underlying Datastore/Logstore/MessageQueue

* adds tests for closing agent.DataAccess and Datastore
This commit is contained in:
Gerardo Viedma
2018-05-21 11:28:21 +01:00
committed by GitHub
parent 105d9b8f1d
commit ea1f94253f
19 changed files with 180 additions and 12 deletions

View File

@@ -347,3 +347,10 @@ func (mq *BoltDbMQ) Delete(ctx context.Context, job *models.Call) error {
return nil
})
}
// Close shuts down the bolt db connection and
// stops the goroutine associated with the ticker
func (mq *BoltDbMQ) Close() error {
mq.ticker.Stop()
return mq.db.Close()
}

View File

@@ -192,3 +192,9 @@ func (mq *MemoryMQ) Delete(ctx context.Context, job *models.Call) error {
log.Debugln("Deleted")
return nil
}
// Close stops the associated goroutines by stopping the ticker
func (mq *MemoryMQ) Close() error {
mq.Ticker.Stop()
return nil
}

View File

@@ -24,3 +24,7 @@ func (mock *Mock) Reserve(context.Context) (*models.Call, error) {
func (mock *Mock) Delete(context.Context, *models.Call) error {
return nil
}
func (mock *Mock) Close() error {
return nil
}

View File

@@ -60,3 +60,8 @@ func (m *metricMQ) Delete(ctx context.Context, t *models.Call) error {
defer span.End()
return m.mq.Delete(ctx, t)
}
// Close closes the underlying message queue
func (m *metricMQ) Close() error {
return m.mq.Close()
}

View File

@@ -307,3 +307,10 @@ func (mq *RedisMQ) Delete(ctx context.Context, job *models.Call) error {
_, err = conn.Do("HDEL", "timeout", resID)
return err
}
// Close shuts down the redis connection pool and
// stops the goroutine associated with the ticker
func (mq *RedisMQ) Close() error {
mq.ticker.Stop()
return mq.pool.Close()
}