This repository has been archived on 2020-09-27 . You can view files and clone it, but cannot push or open issues or pull requests.
2017-05-03 08:02:29 +02:00
// Package with supporting functionality to run the microservice
2017-04-07 11:56:28 +02:00
package runtime
import (
"time"
"github.com/genofire/hs_master-kss-monolith/lib/database"
"github.com/genofire/hs_master-kss-monolith/lib/worker"
"github.com/genofire/hs_master-kss-monolith/models"
)
2017-05-03 08:02:29 +02:00
// Function to create a Worker and to unlock goods
2017-04-07 11:56:28 +02:00
func NewGoodReleaseWorker ( grc models . GoodReleaseConfig ) * worker . Worker {
return worker . NewWorker ( grc . Every . Duration , func ( ) {
goodRelease ( grc . After . Duration )
} )
}
2017-05-03 08:02:29 +02:00
// Function to unlock goods after a specified time
2017-04-07 11:56:28 +02:00
func goodRelease ( unlockAfter time . Duration ) int64 {
res := database . Write . Model ( & models . Good { } ) . Where ( "locked_secret is not NULL and locked_at < ?" , time . Now ( ) . Add ( - unlockAfter ) ) . Updates ( map [ string ] interface { } { "locked_secret" : "" , "locked_at" : nil } )
return res . RowsAffected
}