Add scaffolding for cron trigger support

This commit is contained in:
2023-04-08 14:42:23 -06:00
parent e1382e50ea
commit a9481fa9bc
4 changed files with 171 additions and 0 deletions
+52
View File
@@ -670,3 +670,55 @@ RETURNING id, name, token;`
return s, nil
}
func (db *Database) GetCronsForPipeline(pipelineId uuid.UUID) ([]Cron, error) {
query := `
SELECT id, cron
FROM crons
WHERE pipeline_id=$1;`
var crons []Cron
cronEntrys, err := db.Conn.Query(context.Background(), query, pipelineId)
if err != nil {
return crons, fmt.Errorf("Could not get crons for pipeline with id \"%v\": %w", pipelineId, err)
}
defer cronEntrys.Close()
for cronEntrys.Next() {
var cron Cron
var idStr string
if err := cronEntrys.Scan(
&idStr, &cron.Cron,
); err != nil {
return crons, err
}
cron.Id, err = uuid.Parse(idStr)
if err != nil {
return crons, err
}
crons = append(crons, cron)
}
return crons, nil
}
func (db *Database) AddCronForPipeline(pipelineId uuid.UUID, cron string) error {
query := `
INSERT INTO crons (id, pipeline_id, cron)
VALUES (uuid_generate_v4(), $1, $2);`
_, err := db.Conn.Exec(context.Background(), query, pipelineId, cron)
return err
}
func (db *Database) RemoveCronForPipeline(cronId uuid.UUID) error {
query := `
DELETE FROM crons
WHERE id=$1;`
_, err := db.Conn.Exec(context.Background(), query, cronId)
return err
}