Commit 9af66e0c authored by Gabriel Mazetto's avatar Gabriel Mazetto Committed by Rémy Coutable

Merge branch 'bug/sidekiq-cron-better-error' into 'master'

Improve cron_jobs loading error messages

## What does this MR do?

Improves the error message from "Sidekiq Cron Jobs" plugin, when trying to load a incorrect definition from gitlab config files.

This is the output before the fix:

```
2016-06-08T16:43:19.277Z 2890 TID-gso49ojro INFO: Booting Sidekiq 4.1.2 with redis options {:url=>"unix:/var/run/redis/redis.sock", :namespace=>"resque:gitlab"}
undefined method `delete' for nil:NilClass
/home/git/gitlab/config/initializers/sidekiq.rb:16:in `block (2 levels) in <top (required)>'
/home/git/gitlab/config/initializers/sidekiq.rb:16:in `each'
/home/git/gitlab/config/initializers/sidekiq.rb:16:in `block in <top (required)>'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/sidekiq-4.1.2/lib/sidekiq.rb:70:in `configure_server'
```

This is the output after the fix:

```
2016-07-18T10:53:22.414Z 66332 TID-oxal1bmik INFO: Booting Sidekiq 4.1.4 with redis options {:url=>"redis://localhost:6378", :namespace=>"resque:gitlab"}
Invalid cron_jobs config key: 'registry'. Check your gitlab config file.
/home/git/gitlab/config/initializers/sidekiq.rb:21:in `block (2 levels) in <top (required)>'
/home/git/gitlab/config/initializers/sidekiq.rb:17:in `each'
/home/git/gitlab/config/initializers/sidekiq.rb:17:in `block in <top (required)>'
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/ruby-2.1.8/gems/sidekiq-4.1.4/lib/sidekiq.rb:70:in `configure_server'
```

Fixes #18378

## Are there points in the code the reviewer needs to double check?

No

## Why was this MR needed?

Original error doesn't give any hint on where the problem can be, so the user can't easily troubleshoot unless he knows implementation details.

## What are the relevant issue numbers?

#18378

## Does this MR meet the acceptance criteria?

- [ ] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- [ ] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)
- [ ] API support added
- Tests
  - [ ] Added for this feature/bug
  - [ ] All builds are passing
- [ ] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [ ] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [ ] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

See merge request !5318
parent 9a631d31
......@@ -118,6 +118,7 @@ v 8.10.0 (unreleased)
- Fix last update timestamp on issues not preserved on gitlab.com and project imports
- Fix issues importing projects from EE to CE
- Fix creating group with space in group path
- Improve cron_jobs loading error messages !5318
- Create Todos for Issue author when assign or mention himself (Katarzyna Kobierska)
- Limit the number of retries on error to 3 for exporting projects
- Allow empty repositories on project import/export
......
......@@ -13,7 +13,14 @@ Sidekiq.configure_server do |config|
# UGLY Hack to get nested hash from settingslogic
cron_jobs = JSON.parse(Gitlab.config.cron_jobs.to_json)
# UGLY hack: Settingslogic doesn't allow 'class' key
cron_jobs.each { |k, v| cron_jobs[k]['class'] = cron_jobs[k].delete('job_class') }
cron_jobs_required_keys = %w(job_class cron)
cron_jobs.each do |k, v|
if cron_jobs[k] && cron_jobs_required_keys.all? { |s| cron_jobs[k].key?(s) }
cron_jobs[k]['class'] = cron_jobs[k].delete('job_class')
else
raise("Invalid cron_jobs config key: '#{k}'. Check your gitlab config file.")
end
end
Sidekiq::Cron::Job.load_from_hash! cron_jobs
# Database pool should be at least `sidekiq_concurrency` + 2
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment