Skip to content

Commit

Permalink
✨ Change the locker initialize (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
tosone authored May 1, 2024
1 parent 03561ec commit 1de23de
Show file tree
Hide file tree
Showing 18 changed files with 318 additions and 289 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ WHITE := $(shell tput -Txterm setaf 7)
CYAN := $(shell tput -Txterm setaf 6)
RESET := $(shell tput -Txterm sgr0)

GOLDFLAGS += -X github.com/go-sigma/sigma/pkg/version.Version=$(shell git describe --tags --dirty --always)
GOLDFLAGS += -X github.com/go-sigma/sigma/pkg/version.Version=$(shell git describe --tags --always)
GOLDFLAGS += -X github.com/go-sigma/sigma/pkg/version.BuildDate=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
GOLDFLAGS += -X github.com/go-sigma/sigma/pkg/version.GitHash=$(shell git rev-parse --short HEAD)
GOFLAGS = -ldflags '-s -w $(GOLDFLAGS)' -trimpath
Expand Down
7 changes: 7 additions & 0 deletions cmd/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/go-sigma/sigma/pkg/dal"
"github.com/go-sigma/sigma/pkg/inits"
"github.com/go-sigma/sigma/pkg/logger"
"github.com/go-sigma/sigma/pkg/modules/locker"
"github.com/go-sigma/sigma/pkg/utils/ptr"
)

Expand All @@ -45,6 +46,12 @@ var distributionCmd = &cobra.Command{

config := ptr.To(configs.GetConfiguration())

err = locker.Initialize(config)
if err != nil {
log.Error().Err(err).Msg("Initialize locker with error")
return
}

err = dal.Initialize(config)
if err != nil {
log.Error().Err(err).Msg("Initialize database with error")
Expand Down
7 changes: 7 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/go-sigma/sigma/pkg/dal"
"github.com/go-sigma/sigma/pkg/inits"
"github.com/go-sigma/sigma/pkg/logger"
"github.com/go-sigma/sigma/pkg/modules/locker"
"github.com/go-sigma/sigma/pkg/utils/ptr"
)

Expand All @@ -44,6 +45,12 @@ var serverCmd = &cobra.Command{

config := ptr.To(configs.GetConfiguration())

err = locker.Initialize(config)
if err != nil {
log.Error().Err(err).Msg("Initialize locker with error")
return
}

err = dal.Initialize(config)
if err != nil {
log.Error().Err(err).Msg("Initialize database with error")
Expand Down
7 changes: 7 additions & 0 deletions cmd/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/go-sigma/sigma/pkg/dal"
"github.com/go-sigma/sigma/pkg/inits"
"github.com/go-sigma/sigma/pkg/logger"
"github.com/go-sigma/sigma/pkg/modules/locker"
"github.com/go-sigma/sigma/pkg/utils/ptr"
)

Expand All @@ -44,6 +45,12 @@ var workerCmd = &cobra.Command{

config := ptr.To(configs.GetConfiguration())

err = locker.Initialize(config)
if err != nil {
log.Error().Err(err).Msg("Initialize locker with error")
return
}

err = dal.Initialize(config)
if err != nil {
log.Error().Err(err).Msg("Initialize database with error")
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ go 1.22.0
require (
code.gitea.io/sdk/gitea v0.18.0
github.com/BurntSushi/toml v1.3.2
github.com/IBM/sarama v1.43.1
github.com/IBM/sarama v1.43.2
github.com/Masterminds/sprig/v3 v3.2.3
github.com/alicebob/miniredis/v2 v2.32.1
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
github.com/anchore/syft v1.0.1
github.com/aquasecurity/trivy v0.49.1
github.com/aws/aws-sdk-go v1.51.25
github.com/aws/aws-sdk-go v1.51.32
github.com/caarlos0/env/v9 v9.0.0
github.com/casbin/casbin/v2 v2.87.1
github.com/casbin/casbin/v2 v2.88.0
github.com/casbin/gorm-adapter/v3 v3.24.0
github.com/containers/podman/v5 v5.0.2
github.com/deckarep/golang-set/v2 v2.6.0
Expand All @@ -30,7 +30,7 @@ require (
github.com/go-resty/resty/v2 v2.12.0
github.com/go-sql-driver/mysql v1.8.1
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/golang-migrate/migrate/v4 v4.17.0
github.com/golang-migrate/migrate/v4 v4.17.1
github.com/google/go-github/v53 v53.2.0
github.com/google/uuid v1.6.0
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
Expand All @@ -46,7 +46,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.22
github.com/mholt/archiver/v3 v3.5.1
github.com/moby/buildkit v0.13.1
github.com/opencontainers/distribution-spec/specs-go v0.0.0-20240325152230-75d28161dfed
github.com/opencontainers/distribution-spec/specs-go v0.0.0-20240425175330-d679e21df4fb
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0
github.com/redis/go-redis/v9 v9.5.1
Expand Down Expand Up @@ -74,7 +74,7 @@ require (
gorm.io/driver/postgres v1.5.7
gorm.io/driver/sqlite v1.5.5
gorm.io/gen v0.3.26
gorm.io/gorm v1.25.9
gorm.io/gorm v1.25.10
gorm.io/plugin/dbresolver v1.5.1
gorm.io/plugin/soft_delete v1.2.1
k8s.io/api v0.30.0
Expand Down Expand Up @@ -225,7 +225,7 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
Expand Down
32 changes: 16 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/IBM/sarama v1.43.1 h1:Z5uz65Px7f4DhI/jQqEm/tV9t8aU+JUdTyW/K/fCXpA=
github.com/IBM/sarama v1.43.1/go.mod h1:GG5q1RURtDNPz8xxJs3mgX6Ytak8Z9eLhAkJPObe2xE=
github.com/IBM/sarama v1.43.2 h1:HABeEqRUh32z8yzY2hGB/j8mHSzC/HA9zlEjqFNCzSw=
github.com/IBM/sarama v1.43.2/go.mod h1:Kyo4WkF24Z+1nz7xeVUFWIuKVV8RS3wM8mkvPKMdXFQ=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
Expand Down Expand Up @@ -225,8 +225,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/aws/aws-sdk-go v1.51.25 h1:DjTT8mtmsachhV6yrXR8+yhnG6120dazr720nopRsls=
github.com/aws/aws-sdk-go v1.51.25/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go v1.51.32 h1:A6mPui7QP4mwmovyzgtdedbRbNur1Iu0/El7hBWNHms=
github.com/aws/aws-sdk-go v1.51.32/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go-v2 v1.26.0 h1:/Ce4OCiM3EkpW7Y+xUnfAFpchU78K7/Ug01sZni9PgA=
github.com/aws/aws-sdk-go-v2 v1.26.0/go.mod h1:35hUlJVYd+M++iLI3ALmVwMOyRYMmRqUXpTtRGW+K9I=
github.com/aws/aws-sdk-go-v2/config v1.27.9 h1:gRx/NwpNEFSk+yQlgmk1bmxxvQ5TyJ76CWXs9XScTqg=
Expand Down Expand Up @@ -288,8 +288,8 @@ github.com/buildkite/interpolate v0.0.0-20200526001904-07f35b4ae251 h1:k6UDF1uPY
github.com/buildkite/interpolate v0.0.0-20200526001904-07f35b4ae251/go.mod h1:gbPR1gPu9dB96mucYIR7T3B7p/78hRVSOuzIWLHK2Y4=
github.com/caarlos0/env/v9 v9.0.0 h1:SI6JNsOA+y5gj9njpgybykATIylrRMklbs5ch6wO6pc=
github.com/caarlos0/env/v9 v9.0.0/go.mod h1:ye5mlCVMYh6tZ+vCgrs/B95sj88cg5Tlnc0XIzgZ020=
github.com/casbin/casbin/v2 v2.87.1 h1:7H+ENAfYt3HmZJVw++tJsxx/ko7WEHsfNzpOdYTkpYo=
github.com/casbin/casbin/v2 v2.87.1/go.mod h1:jX8uoN4veP85O/n2674r2qtfSXI6myvxW85f6TH50fw=
github.com/casbin/casbin/v2 v2.88.0 h1:JFHId/aIFvNvPnTwUP+tTtVAjSh3eidslFzy+5LpSeU=
github.com/casbin/casbin/v2 v2.88.0/go.mod h1:jX8uoN4veP85O/n2674r2qtfSXI6myvxW85f6TH50fw=
github.com/casbin/gorm-adapter/v3 v3.24.0 h1:WeLetCTkS1V4zpqF+UJ87PnDOYvdA8K3qp+T/Fj31+E=
github.com/casbin/gorm-adapter/v3 v3.24.0/go.mod h1:aftWi0cla0CC1bHQVrSFzBcX/98IFK28AvuPppCQgTs=
github.com/casbin/govaluate v1.1.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
Expand Down Expand Up @@ -412,8 +412,8 @@ github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczC
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dhui/dktest v0.4.0 h1:z05UmuXZHO/bgj/ds2bGMBu8FI4WA+Ag/m3ghL+om7M=
github.com/dhui/dktest v0.4.0/go.mod h1:v/Dbz1LgCBOi2Uki2nUqLBGa83hWBGFMu5MrgMDCc78=
github.com/dhui/dktest v0.4.1 h1:/w+IWuDXVymg3IrRJCHHOkMK10m9aNVMOyD0X12YVTg=
github.com/dhui/dktest v0.4.1/go.mod h1:DdOqcUpL7vgyP4GlF3X3w7HbSlz8cEQzwewPveYEQbA=
github.com/digitorus/pkcs7 v0.0.0-20230713084857-e76b763bdc49/go.mod h1:SKVExuS+vpu2l9IoOc0RwqE7NYnb0JlcFHFnEJkVDzc=
github.com/digitorus/pkcs7 v0.0.0-20230818184609-3a137a874352 h1:ge14PCmCvPjpMQMIAH7uKg0lrtNSOdpYsRXlwk3QbaE=
github.com/digitorus/pkcs7 v0.0.0-20230818184609-3a137a874352/go.mod h1:SKVExuS+vpu2l9IoOc0RwqE7NYnb0JlcFHFnEJkVDzc=
Expand Down Expand Up @@ -605,8 +605,8 @@ github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w
github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang-migrate/migrate/v4 v4.17.0 h1:rd40H3QXU0AA4IoLllFcEAEo9dYKRHYND2gB4p7xcaU=
github.com/golang-migrate/migrate/v4 v4.17.0/go.mod h1:+Cp2mtLP4/aXDTKb9wmXYitdrNx2HGs45rbWAo6OsKM=
github.com/golang-migrate/migrate/v4 v4.17.1 h1:4zQ6iqL6t6AiItphxJctQb3cFqWiSpMnX7wLTPnnYO4=
github.com/golang-migrate/migrate/v4 v4.17.1/go.mod h1:m8hinFyWBn0SA4QKHuKh175Pm9wjmxj3S2Mia7dbXzM=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
Expand Down Expand Up @@ -928,8 +928,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.11.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg=
github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/klauspost/pgzip v1.2.6 h1:8RXeL5crjEUFnR2/Sn6GJNWtSQ3Dk8pq4CL3jvdDyjU=
Expand Down Expand Up @@ -1098,8 +1098,8 @@ github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo=
github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0=
github.com/open-policy-agent/opa v0.63.0 h1:ztNNste1v8kH0/vJMJNquE45lRvqwrM5mY9Ctr9xIXw=
github.com/open-policy-agent/opa v0.63.0/go.mod h1:9VQPqEfoB2N//AToTxzZ1pVTVPUoF2Mhd64szzjWPpU=
github.com/opencontainers/distribution-spec/specs-go v0.0.0-20240325152230-75d28161dfed h1:OeyovBjoru7XmumCdYu7m0H1FvIr3KUK3SXptdwkD8E=
github.com/opencontainers/distribution-spec/specs-go v0.0.0-20240325152230-75d28161dfed/go.mod h1:Va0IMqkjv62YSEytL4sgxrkiD9IzU0T0bX/ZZEtMnSQ=
github.com/opencontainers/distribution-spec/specs-go v0.0.0-20240425175330-d679e21df4fb h1:GmsG0YNb76gvslFVrJQfFmuio4bKYUcJniFOGX9lIVs=
github.com/opencontainers/distribution-spec/specs-go v0.0.0-20240425175330-d679e21df4fb/go.mod h1:Va0IMqkjv62YSEytL4sgxrkiD9IzU0T0bX/ZZEtMnSQ=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
Expand Down Expand Up @@ -2047,8 +2047,8 @@ gorm.io/gorm v1.25.0/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.9 h1:wct0gxZIELDk8+ZqF/MVnHLkA1rvYlBWUMv2EdsK1g8=
gorm.io/gorm v1.25.9/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s=
gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/hints v1.1.2 h1:b5j0kwk5p4+3BtDtYqqfY+ATSxjj+6ptPgVveuynn9o=
gorm.io/hints v1.1.2/go.mod h1:/ARdpUHAtyEMCh5NNi3tI7FsGh+Cj/MIUlvNxCNCFWg=
gorm.io/plugin/dbresolver v1.5.1 h1:s9Dj9f7r+1rE3nx/Ywzc85nXptUEaeOO0pt27xdopM8=
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmds/distribution/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/go-sigma/sigma/pkg/configs"
"github.com/go-sigma/sigma/pkg/consts"
"github.com/go-sigma/sigma/pkg/graceful"
"github.com/go-sigma/sigma/pkg/handlers"
"github.com/go-sigma/sigma/pkg/inits"
"github.com/go-sigma/sigma/pkg/middlewares"
Expand Down Expand Up @@ -103,5 +104,7 @@ func Serve() error {
log.Error().Err(err).Msg("Server shutdown failed")
}

graceful.Shutdown()

return nil
}
3 changes: 3 additions & 0 deletions pkg/cmds/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/go-sigma/sigma/pkg/builder"
"github.com/go-sigma/sigma/pkg/configs"
"github.com/go-sigma/sigma/pkg/consts"
"github.com/go-sigma/sigma/pkg/graceful"
"github.com/go-sigma/sigma/pkg/handlers"
"github.com/go-sigma/sigma/pkg/inits"
"github.com/go-sigma/sigma/pkg/middlewares"
Expand Down Expand Up @@ -190,5 +191,7 @@ func Serve(serverConfig ServerConfig) error {
log.Error().Err(err).Msg("Server shutdown failed")
}

graceful.Shutdown()

return nil
}
3 changes: 3 additions & 0 deletions pkg/cmds/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/go-sigma/sigma/pkg/builder"
"github.com/go-sigma/sigma/pkg/configs"
"github.com/go-sigma/sigma/pkg/consts"
"github.com/go-sigma/sigma/pkg/graceful"
"github.com/go-sigma/sigma/pkg/middlewares"
"github.com/go-sigma/sigma/pkg/modules/workq"
"github.com/go-sigma/sigma/pkg/types/enums"
Expand Down Expand Up @@ -78,5 +79,7 @@ func Worker() error {
log.Error().Err(err).Msg("Server shutdown failed")
}

graceful.Shutdown()

return nil
}
10 changes: 2 additions & 8 deletions pkg/cronjob/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,14 @@ type builderRunner struct {
}

func (r builderRunner) runner(ctx context.Context, tw timewheel.TimeWheel) {
locker, err := locker.New(r.config)
if err != nil {
log.Error().Err(err).Msg("New locker failed")
return
}
ctx, ctxCancel := context.WithCancel(context.Background())
ctx, ctxCancel := context.WithCancel(log.Logger.WithContext(ctx))
defer ctxCancel()
err = locker.AcquireWithRenew(ctx, consts.LockerCronjobBuilder, time.Second*3, time.Second*5)
err := locker.Locker.AcquireWithRenew(ctx, consts.LockerCronjobBuilder, time.Second*3, time.Second*5)
if err != nil {
log.Error().Err(err).Msg("Cronjob builder get locker failed")
return
}

ctx = log.Logger.WithContext(ctx)
builderService := r.builderServiceFactory.New()
builderObjs, err := builderService.GetByNextTrigger(ctx, time.Now(), cronjob.MaxJob)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion pkg/dal/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ import (
"github.com/go-sigma/sigma/pkg/dal/dao"
"github.com/go-sigma/sigma/pkg/dal/models"
"github.com/go-sigma/sigma/pkg/logger"
"github.com/go-sigma/sigma/pkg/modules/locker"
"github.com/go-sigma/sigma/pkg/types/enums"
)

func TestAuth(t *testing.T) {
logger.SetLevel("debug")

err := locker.Initialize(configs.Configuration{})
assert.NoError(t, err)

dbPath := fmt.Sprintf("%s.db", gonanoid.MustGenerate("abcdefghijklmnopqrstuvwxyz", 6))

assert.NoError(t, dal.Initialize(configs.Configuration{
Expand All @@ -54,7 +58,7 @@ func TestAuth(t *testing.T) {
added, _ := dal.AuthEnforcer.AddPolicy(enums.NamespaceRoleManager.String(), "library", "DS$*/**$manifests$*", "public", "(GET)|(HEAD)", "allow")
assert.True(t, added)

_, err := namespaceMemberService.AddNamespaceMember(ctx, 1, models.Namespace{ID: 1, Name: "library"}, enums.NamespaceRoleManager)
_, err = namespaceMemberService.AddNamespaceMember(ctx, 1, models.Namespace{ID: 1, Name: "library"}, enums.NamespaceRoleManager)
assert.NoError(t, err)
err = dal.AuthEnforcer.LoadPolicy()
assert.NoError(t, err)
Expand Down
6 changes: 1 addition & 5 deletions pkg/dal/dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,9 @@ func Initialize(config configs.Configuration) error {
return err
}

locker, err := locker.New(config)
if err != nil {
return err
}
ctx, ctxCancel := context.WithCancel(context.Background())
defer ctxCancel()
err = locker.AcquireWithRenew(ctx, consts.LockerMigration, time.Second*3, time.Second*5)
err = locker.Locker.AcquireWithRenew(ctx, consts.LockerMigration, time.Second*3, time.Second*5)
if err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/graceful/graceful.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ func Shutdown() {
return runAtShutdown[i].index < runAtShutdown[j].index
})

ctx, ctxCancel := context.WithTimeout(context.Background(), gracefulShutdownTimeout)
gCtx, gCtxCancel := context.WithTimeout(context.Background(), gracefulShutdownTimeout)

waitGroupDone := make(chan struct{})
go func() {
for _, item := range runAtShutdown {
select {
case <-ctx.Done():
case <-gCtx.Done():
return
default:
}
Expand All @@ -81,10 +81,10 @@ func Shutdown() {
waitGroup.Done()
err := recover()
if err != nil {
log.Error().Msgf("Panic during shuting down %s", name)
log.Error().Msgf("Panic during shutting down %s", name)
}
}()
log.Info().Str("name", name).Msg("Shuting down")
log.Info().Str("name", name).Msg("Shutting down")
f()
}(item.name, item.f)
waitGroup.Wait()
Expand All @@ -93,9 +93,9 @@ func Shutdown() {
}()

select {
case <-ctx.Done():
log.Error().Msg("Timeout shuting down")
case <-gCtx.Done():
log.Error().Msg("Timeout shutting down")
case <-waitGroupDone:
}
ctxCancel()
gCtxCancel()
}
6 changes: 1 addition & 5 deletions pkg/inits/baseimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,9 @@ func initBaseimage(config configs.Configuration) error {
log.Info().Msg("Baseimage not found, skip push image")
return nil
}
locker, err := locker.New(config)
if err != nil {
return err
}
ctx, ctxCancel := context.WithCancel(context.Background())
defer ctxCancel()
err = locker.AcquireWithRenew(ctx, consts.LockerBaseimage, time.Second*3, time.Second*5)
err := locker.Locker.AcquireWithRenew(ctx, consts.LockerBaseimage, time.Second*3, time.Second*5)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 1de23de

Please sign in to comment.