Get rid of old apps_list stuff, we ain't gonna need it

This commit is contained in:
Alexandre Aubin 2021-03-01 20:10:58 +01:00
parent 0136788358
commit 21514377c4
3 changed files with 108 additions and 116 deletions

View file

@ -7,7 +7,6 @@ class Repo(peewee.Model):
name = peewee.CharField() # TODO make this uniq/index name = peewee.CharField() # TODO make this uniq/index
url = peewee.CharField() url = peewee.CharField()
revision = peewee.CharField(null=True) revision = peewee.CharField(null=True)
app_list = peewee.CharField(null=True)
state = peewee.CharField(choices=( state = peewee.CharField(choices=(
('working', 'Working'), ('working', 'Working'),

26
run.py
View file

@ -93,9 +93,7 @@ jinja.env.variable_end_string = '}>'
jinja.env.comment_start_string = '<#' jinja.env.comment_start_string = '<#'
jinja.env.comment_end_string = '#>' jinja.env.comment_end_string = '#>'
APPS_LISTS = { APPS_LIST = "https://app.yunohost.org/default/v2/apps.json"
"Apps": "https://app.yunohost.org/apps.json",
}
subscriptions = defaultdict(list) subscriptions = defaultdict(list)
@ -197,18 +195,18 @@ async def monitor_apps_lists(type="stable", dont_monitor_git=False):
commit_sha = data.decode().strip().replace("\t", " ").split(" ")[0] commit_sha = data.decode().strip().replace("\t", " ").split(" ")[0]
return commit_sha return commit_sha
for app_list_name, url in APPS_LISTS.items():
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
task_logger.info(f"Downloading {app_list_name}.json...") task_logger.info(f"Downloading applist...")
async with session.get(url) as resp: async with session.get(APPS_LIST) as resp:
data = await resp.json() data = await resp.json()
data = data["apps"]
repos = {x.name: x for x in Repo.select().where(Repo.app_list == app_list_name)} repos = {x.name: x for x in Repo.select()}
for app_id, app_data in data.items(): for app_id, app_data in data.items():
commit_sha = await get_master_commit_sha(app_data["git"]["url"]) commit_sha = await get_master_commit_sha(app_data["git"]["url"])
if app_data["state"] not in ("working", "validated"): if app_data["state"] not in "working":
task_logger.debug(f"skip {app_id} because state is {app_data['state']}") task_logger.debug(f"skip {app_id} because state is {app_data['state']}")
continue continue
@ -257,7 +255,7 @@ async def monitor_apps_lists(type="stable", dont_monitor_git=False):
await create_job(app_id, repo.url) await create_job(app_id, repo.url)
repo_state = "working" if app_data["state"] in ("working", "validated") else "other_than_working" repo_state = "working" if app_data["state"] == "working" else "other_than_working"
if repo.state != repo_state: if repo.state != repo_state:
repo.state = repo_state repo.state = repo_state
@ -277,13 +275,12 @@ async def monitor_apps_lists(type="stable", dont_monitor_git=False):
# new app # new app
elif app_id not in repos: elif app_id not in repos:
task_logger.info(f"New application detected: {app_id} in {app_list_name}" + (", scheduling a new job" if not dont_monitor_git else "")) task_logger.info(f"New application detected: {app_id} " + (", scheduling a new job" if not dont_monitor_git else ""))
repo = Repo.create( repo = Repo.create(
name=app_id, name=app_id,
url=app_data["git"]["url"], url=app_data["git"]["url"],
revision=commit_sha, revision=commit_sha,
app_list=app_list_name, state="working" if app_data["state"] == "working" else "other_than_working",
state="working" if app_data["state"] in ("working", "validated") else "other_than_working",
random_job_day=random.randint(1, 28), random_job_day=random.randint(1, 28),
) )
@ -319,7 +316,7 @@ async def monitor_apps_lists(type="stable", dont_monitor_git=False):
"data": data, "data": data,
}, ["jobs", f"job-{job_id}", f"app-jobs-{job.url_or_path}"]) }, ["jobs", f"job-{job_id}", f"app-jobs-{job.url_or_path}"])
task_logger.info(f"Delete application {repo_name} because it has been removed from the {app_list_name} apps list.") task_logger.info(f"Delete application {repo_name} because it has been removed from the apps list.")
data = model_to_dict(repo) data = model_to_dict(repo)
repo.delete_instance() repo.delete_instance()
@ -605,7 +602,6 @@ async def ws_apps(request, websocket):
"name", "name",
"url", "url",
"revision", "revision",
"app_list",
"state", "state",
"random_job_day", "random_job_day",
"job_id", "job_id",
@ -653,7 +649,6 @@ async def ws_apps(request, websocket):
"name": x.name, "name": x.name,
"url": x.url, "url": x.url,
"revision": x.revision, "revision": x.revision,
"app_list": x.app_list,
"state": x.state, "state": x.state,
"random_job_day": x.random_job_day, "random_job_day": x.random_job_day,
"job_id": x.job_id, "job_id": x.job_id,
@ -673,7 +668,6 @@ async def ws_apps(request, websocket):
"name": repo.name, "name": repo.name,
"url": repo.url, "url": repo.url,
"revision": repo.revision, "revision": repo.revision,
"app_list": repo.app_list,
"state": repo.state, "state": repo.state,
"random_job_day": repo.random_job_day, "random_job_day": repo.random_job_day,
"job_id": None, "job_id": None,

View file

@ -113,7 +113,6 @@
Vue.set(app.apps[i], 'state', data.state); Vue.set(app.apps[i], 'state', data.state);
Vue.set(app.apps[i], 'url', data.url); Vue.set(app.apps[i], 'url', data.url);
Vue.set(app.apps[i], 'revision', data.revision); Vue.set(app.apps[i], 'revision', data.revision);
Vue.set(app.apps[i], 'app_list', data.app_list);
Vue.set(app.apps[i], 'random_job_day', data.random_job_day); Vue.set(app.apps[i], 'random_job_day', data.random_job_day);
break; break;
} }