Skip to content

Commit

Permalink
set dbs.GlobalLog to be used in go (migration) routines
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Aug 29, 2022
1 parent a48d96a commit 62646dc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dbs/dbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ import (

"github.com/dmwm/dbs2go/utils"
validator "github.com/go-playground/validator/v10"
"github.com/vkuznet/auth-proxy-server/logging"
)

// GlobalLog represents global rorate log object
var GlobalLog *logging.RotateLogWriter

// API structure represents DBS API. Each API has reader (to read
// HTTP POST payload), HTTP writer to write results back to client,
// HTTP context, input HTTP GET paramers, separator for writer,
Expand Down
4 changes: 4 additions & 0 deletions dbs/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,10 @@ func (a *API) SubmitMigration() error {
// the code is based on the following example:
// https://medium.com/geekculture/timeout-context-in-go-e88af0abd08d
func StartMigrationRequest(rec MigrationRequest) {
// set GlobalLog if it is set
if GlobalLog != nil {
log.SetOutput(GlobalLog)
}
// setup context with timeout
ctx, cancel := context.WithTimeout(
context.Background(),
Expand Down
1 change: 1 addition & 0 deletions dbs/migration_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func (r *MigrationRequest) Decode(reader io.Reader) error {

// MigrationRequests fetches migration requests from migration table
func MigrationRequests(mid int64) ([]MigrationRequest, error) {
log.Println("process migration request", mid)
var records []MigrationRequest

// query MigrationRequest table and fetch all non-completed requests
Expand Down
1 change: 1 addition & 0 deletions web/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ func Server(configFile string) {
if err == nil {
rotlogs := logging.RotateLogWriter{RotateLogs: rl}
log.SetOutput(rotlogs)
dbs.GlobalLog = &rotlogs
} else {
log.Println("ERROR: unable to get rotatelogs", err)
}
Expand Down

0 comments on commit 62646dc

Please sign in to comment.