Skip to content

Instantly share code, notes, and snippets.

@vinitkumar
Created January 4, 2019 12:48
Show Gist options
  • Save vinitkumar/e3eaaf6d2f59ed2f02c9d0fff9c54875 to your computer and use it in GitHub Desktop.
Save vinitkumar/e3eaaf6d2f59ed2f02c9d0fff9c54875 to your computer and use it in GitHub Desktop.
import json
import subprocess
import pprint
"""
The goal of this task is to modify the web workers to 2 and timeout to
something like 30 seconds, so that the worker do not cross memory limit
settings['DJANGO_WEB_WORKERS'] = env('DJANGO_WEB_WORKERS', 3)
settings['DJANGO_WEB_MAX_REQUESTS'] = env('DJANGO_WEB_MAX_REQUESTS', 500)
settings['DJANGO_WEB_TIMEOUT'] = env('DJANGO_WEB_TIMEOUT', 120)
"""
MAX_WORKERS = 2
MAX_TIMEOUT = 25
MAX_REQUESTS = 300
problem_with_mem_schools = [
"12neobsdenbiekurf",
"14emontessori",
"7emontessori",
"barbaraschool",
"barbaraschool2",
"basisschooldetoermalijn",
"basisschoolopavontuur",
"bernadettemariaschool",
"bmdbdiermen",
"bontepael",
"cpokempenkind",
"debronvcpo",
"degoudengriffel",
"deoostpoort",
"derietlandenmarken",
"driekoningenschool",
"hoeksteengiessenburg",
"mariaschool",
"obsdecingel",
"tabijnbareel",
]
"""
Read the schoollist.json file, find the ids and then set env and deploy
"""
with open('/Users/vinitkumar/schoollist.json') as schoollist:
main_obj = schoollist.read()
websites = json.loads(main_obj)['websites']
list_of_school_obj = []
for website in websites:
if website['domain'] in problem_with_mem_schools:
list_of_school_obj.append(
{
'domain': website['domain'],
'id': website['id']
}
)
# pp = pprint.PrettyPrinter(indent=2)
# pp.pprint(list_of_school_obj)
for school in list_of_school_obj:
website_id = school['id']
# print(f"updating the env for school: {school['id']} : {school['domain']}")
# subprocess.call(['divio project env-vars --json --stage=live --set DJANGO_WEB_WORKERS {} --remote-id={}'.format(MAX_WORKERS, website_id)], shell=True)
# subprocess.call(['divio project env-vars --json --stage=live --set DJANGO_WEB_TIMEOUT {} --remote-id={}'.format(MAX_TIMEOUT, website_id)], shell=True)
# subprocess.call(['divio project env-vars --json --stage=live --set DJANGO_WEB_MAX_REQUESTS {} --remote-id={}'.format(MAX_REQUESTS, website_id)], shell=True)
# print("showing updated env variables")
# print("*" * 100)
# subprocess.call(['divio project env-vars --json --stage=live --remote-id={}'.format(website_id)], shell=True)
# print("*" * 100)
print(f"deploying school: {school['id']} : {school['domain']}")
# divio project deploy live --remote-id=$project_id
subprocess.call([' divio project deploy live --remote-id={}'.format(website_id)], shell=True)
subprocess.call([' divio project live --remote-id={}'.format(website_id)], shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment