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