# -*- coding: utf-8 -*-
# Copyright (c) 2020, JINGROW
# For license information, please see license.txt


import jingrow

from jcloud.jcloud.pagetype.site_plan.site_plan import get_plan_config
from jcloud.utils import log_error


def execute():
	sites = jingrow.get_all(
		"Site", fields=["name", "plan"], filters={"status": ("!=", "Archived")}
	)
	for site in sites:
		if not site.plan:
			continue
		plan_config = get_plan_config(site.plan)
		site_pg = jingrow.get_pg("Site", site)
		try:
			site_pg.update_site_config(plan_config)
		except Exception:
			log_error("Rate Limit Patch Failure", site=site.name)
