From 259ef4c8f2605ee5de82dbb70be361273759831a Mon Sep 17 00:00:00 2001 From: rfyiamcool Date: Tue, 14 Nov 2023 14:21:05 +0800 Subject: [PATCH] format: golang style code Signed-off-by: rfyiamcool --- gormlock.go => gorm_lock.go | 11 ++++++++--- gormlockoptions.go => gorm_lock_options.go | 0 gormlock_test.go => gorm_lock_test.go | 2 +- job-lock-struct.go => job_lock_struct.go | 0 4 files changed, 9 insertions(+), 4 deletions(-) rename gormlock.go => gorm_lock.go (89%) rename gormlockoptions.go => gorm_lock_options.go (100%) rename gormlock_test.go => gorm_lock_test.go (99%) rename job-lock-struct.go => job_lock_struct.go (100%) diff --git a/gormlock.go b/gorm_lock.go similarity index 89% rename from gormlock.go rename to gorm_lock.go index cc4f724..b9031e8 100644 --- a/gormlock.go +++ b/gorm_lock.go @@ -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} @@ -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 { @@ -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 } diff --git a/gormlockoptions.go b/gorm_lock_options.go similarity index 100% rename from gormlockoptions.go rename to gorm_lock_options.go diff --git a/gormlock_test.go b/gorm_lock_test.go similarity index 99% rename from gormlock_test.go rename to gorm_lock_test.go index 467a451..52d8ab1 100644 --- a/gormlock_test.go +++ b/gorm_lock_test.go @@ -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) diff --git a/job-lock-struct.go b/job_lock_struct.go similarity index 100% rename from job-lock-struct.go rename to job_lock_struct.go