Skip to content

Commit

Permalink
pass active to list of jobs, formatting postgres locker
Browse files Browse the repository at this point in the history
  • Loading branch information
david-littlefarmer committed May 30, 2024
1 parent 64609f0 commit bbbb66f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion looper.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (l *Looper) AddJob(ctx context.Context, jobInput *Job) (err error) {
Timeout: setDefaultDuration(jobInput.Timeout, time.Minute),
WaitAfterSuccess: setDefaultDuration(jobInput.WaitAfterSuccess, time.Second),
WaitAfterError: setDefaultDuration(jobInput.WaitAfterError, time.Second),
Active: true,
Active: jobInput.Active,
BeforeJob: beforeJob,
AfterJob: afterJob,
AfterJobError: afterJobError,
Expand Down
15 changes: 7 additions & 8 deletions postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,23 @@ const defaultTableName = "looper_lock"

// PostgresLocker provides an implementation of the Locker interface using
// a PostgreSQL table for storage.
func PostgresLocker(ctx context.Context, db *sql.DB, table string) (locker, error) {
err := db.PingContext(ctx)
if err != nil {
func PostgresLocker(ctx context.Context, db *sql.DB, tableName string) (locker, error) {
if err := db.PingContext(ctx); err != nil {
return nil, fmt.Errorf("%w: %v", ErrFailedToConnectToLocker, err)
}

if table == "" {
table = defaultTableName
if tableName == "" {
tableName = defaultTableName
}

// Ensure the lock table exists, create it if necessary
err = createLockTable(ctx, db, table)
if err != nil {
if err := createLockTable(ctx, db, tableName); err != nil {
return nil, err
}

pl := &postgresLocker{
db: db,
table: table,
table: tableName,
}

return pl, nil
Expand Down

0 comments on commit bbbb66f

Please sign in to comment.