redash/migrations/versions/e5c7a4e2df4d_remove_query_tracker_keys.py
Arik Fraimovich 26f0ce0749
New Celery/Queries Execution Status API (#3057)
* Remove QueryTaskTracker

* Remove scheudling of cleanup_tasks

* Add Celery introspection tools

* First iteration of updating the admin API.

* Show more details

* Add option to skip building npm in Dockerfile

* Show started_at

* update the refresh schedule, as it's too fast

* Update Celery monitor to report on all active tasks.

* Update task parsing for new format

* WIP: improved celery status screen

* Fix property name.

* Update counters

* Update tab name

* Update counters names

* Move component to its own file and fix lint issues

* Add migratin to remove Redis keys

* Improve columns layout

* Remove skip_npm_build arg as it's not used anymore.

* Convert query from SQL to Python

* Simplify column definition.

* Show alert on error.
2019-03-10 11:19:31 +02:00

52 lines
1.1 KiB
Python

"""remove_query_tracker_keys
Revision ID: e5c7a4e2df4d
Revises: 98af61feea92
Create Date: 2019-02-27 11:30:15.375318
"""
from alembic import op
import sqlalchemy as sa
from redash import redis_connection
# revision identifiers, used by Alembic.
revision = 'e5c7a4e2df4d'
down_revision = '98af61feea92'
branch_labels = None
depends_on = None
DONE_LIST = 'query_task_trackers:done'
WAITING_LIST = 'query_task_trackers:waiting'
IN_PROGRESS_LIST = 'query_task_trackers:in_progress'
def prune(list_name, keep_count, max_keys=100):
count = redis_connection.zcard(list_name)
if count <= keep_count:
return 0
remove_count = min(max_keys, count - keep_count)
keys = redis_connection.zrange(list_name, 0, remove_count - 1)
redis_connection.delete(*keys)
redis_connection.zremrangebyrank(list_name, 0, remove_count - 1)
return remove_count
def prune_all(list_name):
removed = 1000
while removed > 0:
removed = prune(list_name, 0)
def upgrade():
prune_all(DONE_LIST)
prune_all(WAITING_LIST)
prune_all(IN_PROGRESS_LIST)
def downgrade():
pass