diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-08-25 18:55:13 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-08-25 18:55:13 +0000 |
commit | b5cc8136127326b953663abda962985d111fa250 (patch) | |
tree | 1e95648faace134777dbf8d017572e5ad0803a51 | |
parent | 5087f36d2358e470988df800f3ecfbe556190946 (diff) | |
parent | b752ee8aa93ead6d9e39219444a20761d9f01de5 (diff) | |
download | gitlab-ce-b5cc8136127326b953663abda962985d111fa250.tar.gz |
Merge branch 'drop_post_recieve_jobs' into 'master'
Add rake task to drop a project's PostReceive jobs
If a user pushes so many branches/tags to a project that Sidekiq
gets clogged, you can use this script to drop _all_ PostReceive
jobs for a given project.
See merge request !1030
-rw-r--r-- | lib/tasks/gitlab/sidekiq.rake | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/tasks/gitlab/sidekiq.rake b/lib/tasks/gitlab/sidekiq.rake new file mode 100644 index 00000000000..7e2a6668e59 --- /dev/null +++ b/lib/tasks/gitlab/sidekiq.rake @@ -0,0 +1,47 @@ +namespace :gitlab do + namespace :sidekiq do + QUEUE = 'queue:post_receive' + + desc 'Drop all Sidekiq PostReceive jobs for a given project' + task :drop_post_receive , [:project] => :environment do |t, args| + unless args.project.present? + abort "Please specify the project you want to drop PostReceive jobs for:\n rake gitlab:sidekiq:drop_post_receive[group/project]" + end + project_path = Project.find_with_namespace(args.project).repository.path_to_repo + + Sidekiq.redis do |redis| + unless redis.exists(QUEUE) + abort "Queue #{QUEUE} is empty" + end + + temp_queue = "#{QUEUE}_#{Time.now.to_i}" + redis.rename(QUEUE, temp_queue) + + # At this point, then post_receive queue is empty. It may be receiving + # new jobs already. We will repopulate it with the old jobs, skipping the + # ones we want to drop. + dropped = 0 + while (job = redis.lpop(temp_queue)) do + if repo_path(job) == project_path + dropped += 1 + else + redis.rpush(QUEUE, job) + end + end + # The temp_queue will delete itself after we have popped all elements + # from it + + puts "Dropped #{dropped} jobs containing #{project_path} from #{QUEUE}" + end + end + + def repo_path(job) + job_args = JSON.parse(job)['args'] + if job_args + job_args.first + else + nil + end + end + end +end |