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-04-04 19:28:46 +02:00
package models
import (
"time"
"github.com/genofire/hs_master-kss-monolith/lib/database"
2017-04-05 20:23:29 +02:00
"github.com/genofire/hs_master-kss-monolith/lib/worker"
2017-04-04 19:28:46 +02:00
)
type GoodReleaseConfig struct {
After Duration ` toml:"after" `
2017-04-05 19:03:44 +02:00
Every Duration ` toml:"every" `
2017-04-04 19:28:46 +02:00
}
2017-04-05 20:23:29 +02:00
func NewGoodReleaseWorker ( grc GoodReleaseConfig ) * worker . Worker {
return worker . NewWorker ( grc . Every . Duration , func ( ) {
2017-04-05 19:03:44 +02:00
goodRelease ( grc . After . Duration )
} )
2017-04-04 19:28:46 +02:00
}
func goodRelease ( unlockAfter time . Duration ) int64 {
res := database . Write . Model ( & 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
}