Skip to content

Commit

Permalink
janitor: drop service and add as job
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Spooren <mail@aparcar.org>
  • Loading branch information
aparcar committed May 9, 2023
1 parent 9e493ba commit d9c26ad
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 126 deletions.
18 changes: 17 additions & 1 deletion asu/asu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from flask import Flask, render_template, send_from_directory
from pkg_resources import resource_filename
from prometheus_client import CollectorRegistry, make_wsgi_app
from redis import Redis
from rq import Queue
from werkzeug.middleware.dispatcher import DispatcherMiddleware
from yaml import safe_load

import asu.common
from asu import __version__
from asu.janitor import update
from redis import Redis


def create_app(test_config: dict = None) -> Flask:
Expand Down Expand Up @@ -138,4 +140,18 @@ def stats():
validate_responses=app.config["TESTING"],
)

queue = Queue(
connection=app.config["REDIS_CONN"],
is_async=app.config["ASYNC_QUEUE"],
)
queue.enqueue(
update,
{
"JSON_PATH": app.config["JSON_PATH"],
"BRANCHES": app.config["BRANCHES"],
"UPSTREAM_URL": app.config["UPSTREAM_URL"],
},
job_timeout="10m",
)

return app
7 changes: 2 additions & 5 deletions asu/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@
import requests
from flask import current_app
from podman import PodmanClient


def get_redis():
return current_app.config["REDIS_CONN"]
from rq import Queue, get_current_job


def is_modified(url: str) -> bool:
r = get_redis()
r = get_current_job().connection

modified_local = r.hget("last-modified", url)
if modified_local:
Expand Down
Loading

0 comments on commit d9c26ad

Please sign in to comment.