Skip to content

Commit

Permalink
format: golang style code
Browse files Browse the repository at this point in the history
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
  • Loading branch information
rfyiamcool committed Nov 14, 2023
1 parent 4af7149 commit 259ef4c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions gormlock.go → gorm_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import (
"gorm.io/gorm"
)

var defaultPrecision = time.Second
var (
defaultPrecision = time.Second

StatusRunning = "RUNNING"
StatusFinished = "FINISHED"
)

func NewGormLocker(db *gorm.DB, worker string, options ...LockOption) (gocron.Locker, error) {
gl := &gormLocker{db: db, worker: worker}
Expand All @@ -34,7 +39,7 @@ func (g *gormLocker) Lock(ctx context.Context, key string) (gocron.Lock, error)
JobName: key,
JobIdentifier: ji,
Worker: g.worker,
Status: "RUNNING",
Status: StatusRunning,
}
tx := g.db.Create(cjb)
if tx.Error != nil {
Expand All @@ -58,5 +63,5 @@ type gormLock struct {
}

func (g *gormLock) Unlock(_ context.Context) error {
return g.db.Model(&CronJobLock{ID: g.id}).Updates(&CronJobLock{Status: "FINISHED"}).Error
return g.db.Model(&CronJobLock{ID: g.id}).Updates(&CronJobLock{Status: StatusFinished}).Error
}
File renamed without changes.
2 changes: 1 addition & 1 deletion gormlock_test.go → gorm_lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func TestJobReturningExceptionWhenUnique(t *testing.T) {
JobName: "job",
JobIdentifier: time.Now().Truncate(60 * time.Minute).Format("2006-01-02 15:04:05.000"),
Worker: "local",
Status: "RUNNING",
Status: StatusRunning,
}
require.NoError(t, db.Create(cjb).Error)

Expand Down
File renamed without changes.

0 comments on commit 259ef4c

Please sign in to comment.