~sircmpwn/builds.sr.ht

builds.sr.ht/api/graph/celery.go -rw-r--r-- 954 bytes
48fa5794Dhruvin Gandhi alpine: run setup-timezone conditionally 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package graph

import (
	"context"

	"git.sr.ht/~sircmpwn/core-go/config"

	celery "github.com/gocelery/gocelery"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promauto"
)

var (
	buildsSubmitted = promauto.NewCounter(prometheus.CounterOpts{
		Name: "buildsrht_builds_submited_total",
		Help: "Number of builds submitted",
	})
)

func SubmitJob(ctx context.Context, jobID int, manifest *Manifest) error {
	conf := config.ForContext(ctx)
	clusterRedis, _ := conf.Get("builds.sr.ht", "redis")
	broker := celery.NewRedisCeleryBroker(clusterRedis)
	backend := celery.NewRedisCeleryBackend(clusterRedis)

	// XXX: Maybe we should keep this client instance around and stash it
	// somewhere on the context
	client, err := celery.NewCeleryClient(broker, backend, 1)
	if err != nil {
		panic(err)

	}

	buildsSubmitted.Inc()
	_, err = client.Delay("buildsrht.runner.run_build", jobID, manifest)
	return err
}