~comcloudway/builds.sr.ht

690f1aa16c77e418dc40109cd5e8fdf4a7ed947a — Ignas Kiela 2 years ago 994d5d8
Add build submission and queue monitoring
2 files changed, 11 insertions(+), 1 deletions(-)

M buildsrht/app.py
M buildsrht/runner.py
M buildsrht/app.py => buildsrht/app.py +3 -0
@@ 36,6 36,9 @@ class BuildApp(SrhtFlask):
        self.register_blueprint(secrets)
        self.register_blueprint(gql_blueprint)

        from buildsrht.runner import builds_queue_metrics_collector
        self.metrics_registry.register(builds_queue_metrics_collector)

        @self.context_processor
        def inject():
            return {

M buildsrht/runner.py => buildsrht/runner.py +8 -1
@@ 5,10 5,13 @@ from srht.config import cfg
from srht.database import db
from srht.email import send_email
from srht.oauth import UserType
from srht.metrics import RedisQueueCollector
from prometheus_client import Counter

allow_free = cfg("builds.sr.ht", "allow-free", default="no") == "yes"

runner = Celery('builds', broker=cfg("builds.sr.ht", "redis"), config_source={
builds_broker = cfg("builds.sr.ht", "redis")
runner = Celery('builds', broker=builds_broker, config_source={
    "CELERY_TASK_SERIALIZER": "json",
    "CELERY_ACCEPT_CONTENT": ["json"],
    "CELERY_RESULT_SERIALIZER": "json",


@@ 16,6 19,9 @@ runner = Celery('builds', broker=cfg("builds.sr.ht", "redis"), config_source={
    "CELERY_TASK_PROTOCOL": 1
})

builds_queue_metrics_collector = RedisQueueCollector(builds_broker, "buildsrht_builds", "Number of builds currently in queue")
builds_submitted = Counter("buildsrht_builds_submited", "Number of builds submitted")

def queue_build(job, manifest):
    from buildsrht.types import JobStatus
    job.status = JobStatus.queued


@@ 28,6 34,7 @@ def queue_build(job, manifest):
                cfg("sr.ht", "owner-email"),
                "Cryptocurrency mining attempt on builds.sr.ht")
    else:
        builds_submitted.inc()
        run_build.delay(job.id, manifest.to_dict())

def requires_payment(user):