Skip to content

Instantly share code, notes, and snippets.

@tsucchi
Created November 9, 2017 10:03
Show Gist options
  • Save tsucchi/22533296d7314076cd7c7d648e9f482e to your computer and use it in GitHub Desktop.
Save tsucchi/22533296d7314076cd7c7d648e9f482e to your computer and use it in GitHub Desktop.
闇のツール 優先度調整くん1号
#!/bin/bash
psql -U jobqueue -h rds_for_jobqueue jobqueue -c "update minion_jobs set priority = priority + 1 where id in (select id from minion_jobs where state = 'inactive' and delayed < now() - interval '1 seconds' * 60 * 1 and task in ('Omoi::Job::Ichigou', 'Omoi::Job::Nigou') and subqueue_id in ( select subqueue_id from ( select subqueue_id, count(*) from minion_jobs where delayed < now() - interval '1 seconds' * 60 * 1 and task in ('Omoi::Job::Ichigou', 'Omoi::Job::Nigou') group by subqueue_id having count(*) <= 5 ) as subqueue ) );"
psql -U jobqueue -h rds_for_jobqueue jobqueue -c "update minion_jobs set priority = priority + 1 where id in (select id from minion_jobs where state = 'inactive' and delayed < now() - interval '1 seconds' * 60 * 5 and task in ('Omoi::Job::Ichigou', 'Omoi::Job::Nigou') and subqueue_id in ( select subqueue_id from ( select subqueue_id, count(*) from minion_jobs where delayed < now() - interval '1 seconds' * 60 * 5 and task in ('Omoi::Job::Ichigou', 'Omoi::Job::Nigou') group by subqueue_id having count(*) <= 10 ) as subqueue ) );"
psql -U jobqueue -h rds_for_jobqueue jobqueue -c "update minion_jobs set priority = priority + 1 where id in (select id from minion_jobs where state = 'inactive' and delayed < now() - interval '1 seconds' * 60 * 10 and task in ('Omoi::Job::Ichigou', 'Omoi::Job::Nigou') and subqueue_id in ( select subqueue_id from ( select subqueue_id, count(*) from minion_jobs where delayed < now() - interval '1 seconds' * 60 * 10 and task in ('Omoi::Job::Ichigou', 'Omoi::Job::Nigou') group by subqueue_id having count(*) <= 20 ) as subqueue ) );"
psql -U jobqueue -h rds_for_jobqueue jobqueue -c "update minion_jobs set priority = priority + 1 where id in (select id from minion_jobs where state = 'inactive' and delayed < now() - interval '1 seconds' * 60 * 15 and task in ('Omoi::Job::Ichigou', 'Omoi::Job::Nigou') and subqueue_id in ( select subqueue_id from ( select subqueue_id, count(*) from minion_jobs where delayed < now() - interval '1 seconds' * 60 * 15 and task in ('Omoi::Job::Ichigou', 'Omoi::Job::Nigou') group by subqueue_id having count(*) <= 30 ) as subqueue ) );"
psql -U jobqueue -h rds_for_jobqueue jobqueue -c "update minion_jobs set priority = priority + 1 where id in (select id from minion_jobs where state = 'inactive' and delayed < now() - interval '1 seconds' * 60 * 25 and task in ('Omoi::Job::Ichigou', 'Omoi::Job::Nigou') and subqueue_id in ( select subqueue_id from ( select subqueue_id, count(*) from minion_jobs where delayed < now() - interval '1 seconds' * 60 * 25 and task in ('Omoi::Job::Ichigou', 'Omoi::Job::Nigou') group by subqueue_id having count(*) <= 50 ) as subqueue ) );"
psql -U jobqueue -h rds_for_jobqueue jobqueue -c "update minion_jobs set priority = priority + 1 where id in (select id from minion_jobs where state = 'inactive' and delayed < now() - interval '1 seconds' * 60 * 50 and task in ('Omoi::Job::Ichigou', 'Omoi::Job::Nigou') and subqueue_id in ( select subqueue_id from ( select subqueue_id, count(*) from minion_jobs where delayed < now() - interval '1 seconds' * 60 * 50 and task in ('Omoi::Job::Ichigou', 'Omoi::Job::Nigou') group by subqueue_id having count(*) <= 100 ) as subqueue ) order by delayed limit 50 );"
psql -U jobqueue -h rds_for_jobqueue jobqueue -c "update minion_jobs set priority = priority + 5 where id in (select id from minion_jobs where state = 'inactive' and delayed < now() - interval '1 seconds' * 60 * 5 and task not in ('Omoi::Job::Ichigou', 'Omoi::Job::Nigou') order by delayed limit 500 )"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment