Mercurial > gemma
diff pkg/scheduler/boot.go @ 1660:f32e8a973b48
Scheduler: Moved code to figure out the scheduled jobs per user from the database to a more suited place.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 21 Dec 2018 13:04:46 +0100 |
parents | 85386ad17d34 |
children | 8bbdad3f9af7 |
line wrap: on
line diff
--- a/pkg/scheduler/boot.go Fri Dec 21 12:19:29 2018 +0100 +++ b/pkg/scheduler/boot.go Fri Dec 21 13:04:46 2018 +0100 @@ -29,6 +29,10 @@ SELECT id, username, kind, cron FROM waterway.import_configuration WHERE cron IS NOT NULL` + + scheduledIDsSQL = ` +SELECT id from waterway.import_configuration +WHERE username = $1 AND cron IS NOT NULL` ) func init() { go boot() } @@ -74,3 +78,28 @@ log.Printf("error: %v\n", err) } } + +// ScheduledUserIDs returns the IDs with a schedule for a given user. +func ScheduledUserIDs( + ctx context.Context, + conn *sql.Conn, + user string, +) (map[int64]struct{}, error) { + ids := map[int64]struct{}{} + rows, err := conn.QueryContext(ctx, scheduledIDsSQL, user) + if err != nil { + return nil, nil + } + defer rows.Close() + for rows.Next() { + var id int64 + if err := rows.Scan(&id); err != nil { + return nil, err + } + ids[id] = struct{}{} + } + if err := rows.Err(); err != nil { + return nil, err + } + return ids, nil +}