Clean old url content, use django db connection
This commit is contained in:
@@ -2,6 +2,7 @@ import os
|
||||
import psycopg
|
||||
from .tasks import background_task
|
||||
from django.http import JsonResponse, HttpResponse
|
||||
from django.db import connection
|
||||
|
||||
####################################################################################################
|
||||
def trigger_task(request, task):
|
||||
@@ -15,7 +16,7 @@ def link_list(request):
|
||||
app_url = request.build_absolute_uri()
|
||||
# Tasks
|
||||
links_fetch = ["fetch_feeds", "fetch_parser", "fetch_search", "fetch_missingkids_5", "fetch_missingkids_all"]
|
||||
links_process = ["process_raw_urls_50", "process_error_urls_50", "process_missing_kids_urls_50", "process_missing_kids_urls_all"]
|
||||
links_process = ["process_raw_urls_50", "process_error_urls_50", "process_missing_kids_urls_50", "process_missing_kids_urls_all", "clean_old_url_content_60"]
|
||||
# List of links
|
||||
list_links = \
|
||||
[ os.path.join(app_url, "admin"), os.path.join(app_url, "urls") ] + \
|
||||
@@ -32,7 +33,6 @@ def link_list(request):
|
||||
|
||||
return HttpResponse(html)
|
||||
|
||||
|
||||
####################################################################################################
|
||||
def logs(request, log_type):
|
||||
# Capture output: python manage.py rqstats
|
||||
@@ -45,39 +45,28 @@ def logs(request, log_type):
|
||||
|
||||
####################################################################################################
|
||||
def log_db(request):
|
||||
# TODO: Django connection
|
||||
connection_info = "host={} port={} dbname={} user={} password={} connect_timeout=60".format(
|
||||
os.environ.get("DB_HOST", "localhost"),
|
||||
os.environ.get("DB_PORT", "5432"),
|
||||
os.environ.get("DB_NAME", "matitos"),
|
||||
os.environ.get("DB_USER", "supermatitos"),
|
||||
os.environ.get("DB_PASSWORD", "supermatitos")
|
||||
)
|
||||
|
||||
# Connect to an existing database
|
||||
with psycopg.connect(connection_info) as conn:
|
||||
# Open a cursor to perform database operations
|
||||
with conn.cursor() as cur:
|
||||
# Create URLs table
|
||||
r = cur.execute("""
|
||||
SELECT
|
||||
relname AS "relation",
|
||||
pg_size_pretty (
|
||||
pg_total_relation_size (C .oid)
|
||||
) AS "total_size"
|
||||
FROM
|
||||
pg_class C
|
||||
LEFT JOIN pg_namespace N ON (N.oid = C .relnamespace)
|
||||
WHERE
|
||||
nspname NOT IN (
|
||||
'pg_catalog',
|
||||
'information_schema'
|
||||
)
|
||||
AND C .relkind <> 'i'
|
||||
AND nspname !~ '^pg_toast'
|
||||
ORDER BY
|
||||
pg_total_relation_size (C .oid) DESC
|
||||
LIMIT 100;
|
||||
""").fetchall()
|
||||
with connection.cursor() as cursor:
|
||||
# Create URLs table
|
||||
r = cursor.execute("""
|
||||
SELECT
|
||||
relname AS "relation",
|
||||
pg_size_pretty (
|
||||
pg_total_relation_size (C .oid)
|
||||
) AS "total_size"
|
||||
FROM
|
||||
pg_class C
|
||||
LEFT JOIN pg_namespace N ON (N.oid = C .relnamespace)
|
||||
WHERE
|
||||
nspname NOT IN (
|
||||
'pg_catalog',
|
||||
'information_schema'
|
||||
)
|
||||
AND C .relkind <> 'i'
|
||||
AND nspname !~ '^pg_toast'
|
||||
ORDER BY
|
||||
pg_total_relation_size (C .oid) DESC
|
||||
LIMIT 100;
|
||||
""").fetchall()
|
||||
return HttpResponse( "\n".join([str(e) for e in r]) )
|
||||
|
||||
####################################################################################################
|
||||
Reference in New Issue
Block a user