Mercurial > gemma
comparison 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 |
comparison
equal
deleted
inserted
replaced
1659:897e7cad7e77 | 1660:f32e8a973b48 |
---|---|
27 | 27 |
28 selectImportConfSQL = ` | 28 selectImportConfSQL = ` |
29 SELECT id, username, kind, cron | 29 SELECT id, username, kind, cron |
30 FROM waterway.import_configuration | 30 FROM waterway.import_configuration |
31 WHERE cron IS NOT NULL` | 31 WHERE cron IS NOT NULL` |
32 | |
33 scheduledIDsSQL = ` | |
34 SELECT id from waterway.import_configuration | |
35 WHERE username = $1 AND cron IS NOT NULL` | |
32 ) | 36 ) |
33 | 37 |
34 func init() { go boot() } | 38 func init() { go boot() } |
35 | 39 |
36 // boot starts the scheduler with the configurations from | 40 // boot starts the scheduler with the configurations from |
72 }) | 76 }) |
73 if err != nil { | 77 if err != nil { |
74 log.Printf("error: %v\n", err) | 78 log.Printf("error: %v\n", err) |
75 } | 79 } |
76 } | 80 } |
81 | |
82 // ScheduledUserIDs returns the IDs with a schedule for a given user. | |
83 func ScheduledUserIDs( | |
84 ctx context.Context, | |
85 conn *sql.Conn, | |
86 user string, | |
87 ) (map[int64]struct{}, error) { | |
88 ids := map[int64]struct{}{} | |
89 rows, err := conn.QueryContext(ctx, scheduledIDsSQL, user) | |
90 if err != nil { | |
91 return nil, nil | |
92 } | |
93 defer rows.Close() | |
94 for rows.Next() { | |
95 var id int64 | |
96 if err := rows.Scan(&id); err != nil { | |
97 return nil, err | |
98 } | |
99 ids[id] = struct{}{} | |
100 } | |
101 if err := rows.Err(); err != nil { | |
102 return nil, err | |
103 } | |
104 return ids, nil | |
105 } |