aboutsummaryrefslogtreecommitdiff
path: root/acid.go
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2026-01-10 22:04:54 +0100
committerPřemysl Eric Janouch <p@janouch.name>2026-01-10 22:04:54 +0100
commit07c7317e0b6efbe86958ed8c44c51edca7f3421d (patch)
tree8210dde56cdd0f70cae2cd8b63f86eab3339f196 /acid.go
parent691b3a1a241a0b086a316506c068618b58bcd8c0 (diff)
downloadacid-07c7317e0b6efbe86958ed8c44c51edca7f3421d.tar.gz
acid-07c7317e0b6efbe86958ed8c44c51edca7f3421d.tar.xz
acid-07c7317e0b6efbe86958ed8c44c51edca7f3421d.zip
Avoid duplicating tasks on push
Diffstat (limited to 'acid.go')
-rw-r--r--acid.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/acid.go b/acid.go
index 16322a5..edbe987 100644
--- a/acid.go
+++ b/acid.go
@@ -507,6 +507,28 @@ type GiteaPushEvent struct {
} `json:"repository"`
}
+func getPendingRunnersFor(ctx context.Context, tx *sql.Tx,
+ owner, repo, hash string) (map[string]struct{}, error) {
+ rows, err := tx.QueryContext(ctx, `SELECT DISTINCT runner FROM task
+ WHERE owner = ? AND repo = ? AND hash = ? AND state = ?`,
+ owner, repo, hash, taskStateNew)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+
+ runners := make(map[string]struct{})
+ for rows.Next() {
+ var r string
+ err := rows.Scan(&r)
+ if err != nil {
+ return nil, err
+ }
+ runners[r] = struct{}{}
+ }
+ return runners, rows.Err()
+}
+
func createTasks(ctx context.Context,
owner, repo, hash string, runners []string) error {
tx, err := gDB.BeginTx(ctx, nil)
@@ -515,6 +537,16 @@ func createTasks(ctx context.Context,
}
defer tx.Rollback()
+ // When you push a tag for a commit that has already had its task run,
+ // running it anew may make it receive a new "git describe" value.
+ //
+ // But if the task hasn't managed to run yet and is currently
+ // still enqueued, duplicating it provides nothing.
+ pending, err := getPendingRunnersFor(ctx, tx, owner, repo, hash)
+ if err != nil {
+ return err
+ }
+
stmt, err := tx.Prepare(
`INSERT INTO task(owner, repo, hash, runner, created, changed)
VALUES (?, ?, ?, ?, unixepoch('now'), unixepoch('now'))`)
@@ -523,6 +555,9 @@ func createTasks(ctx context.Context,
}
for _, runner := range runners {
+ if _, ok := pending[runner]; ok {
+ continue
+ }
if _, err := stmt.Exec(owner, repo, hash, runner); err != nil {
return err
}