Git repository import rake task throws an error in GitLab CE 8.16.3

Summary

When following the instructions for importing a git repository via rake task, the import fails with an error about an undefined method perform on the ProjectCacheWorker. The repository is imported into gitlab, but the statistics and details (files, commits, etc.) are incorrect on the project summary page. This started failing this morning, after I upgraded to GitLab CE 8.16.3. Imports were still working before the upgrade yesterday.

Steps to reproduce

  1. Copy a raw git repository to the repository storage path.
  2. Execute gitlab-rake gitlab:import:repos

Expected behavior

Expecting detailed output about the successful repository import, like this:

** Invoke gitlab:import:repos (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute gitlab:import:repos
Processing bnigmann/abi94.git
 * Abi94 (bnigmann/abi94.git) exists
[...]
Processing bnigmann/my-new-repository.git
 * Created my-new-repository (bnigmann/my-new-repository.git)
Done!

Actual behavior

The import task aborts with the following error:

** Invoke gitlab:import:repos (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute gitlab:import:repos
Processing bnigmann/abi94.git
 * Abi94 (bnigmann/abi94.git) exists
[...]
Processing bnigmann/my-new-repository.git
 * Created my-new-repository (bnigmann/my-new-repository.git)
rake aborted!
NoMethodError: undefined method `perform' for ProjectCacheWorker:Class
Did you mean?  perform_at
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/import.rake:66:in `block (5 levels) in <top (required)>'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/import.rake:17:in `each'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/import.rake:17:in `block (4 levels) in <top (required)>'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/import.rake:14:in `each'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/import.rake:14:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/bin/bundle:22:in `load'
/opt/gitlab/embedded/bin/bundle:22:in `<main>'
Tasks: TOP => gitlab:import:repos
(See full trace by running task with --trace)

Results of GitLab application Check

Redacted output of sudo gitlab-rake gitlab:check SANITIZE=true:

# gitlab-rake gitlab:check SANITIZE=true
Checking GitLab Shell ...

GitLab Shell version >= 4.1.1 ? ... OK (4.1.1)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ... 
2/15 ... ok
[...]
7/242 ... ok
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Check GitLab API access: OK
Access to /var/opt/gitlab/.ssh/authorized_keys: OK
Send ping to redis server: OK
gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes
Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking Reply by email ...

Reply by email is disabled in config/gitlab.yml

Checking Reply by email ... Finished

Checking LDAP ...

Server: ldapmain
LDAP authentication... Success
LDAP users with access to your GitLab server (only showing the first 100 results)
[...]

Checking LDAP ... Finished

Checking GitLab ...

Git configured with autocrlf=input? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory setup correctly? ... no
  Try fixing it:
  sudo chown -R git /var/opt/gitlab/gitlab-rails/uploads
  sudo find /var/opt/gitlab/gitlab-rails/uploads -type f -exec chmod 0644 {} \;
  sudo find /var/opt/gitlab/gitlab-rails/uploads -type d -not -path /var/opt/gitlab/gitlab-rails/uploads -exec chmod 0700 {} \;
  For more information see:
  doc/install/installation.md in section "GitLab"
  Please fix the error above and rerun the checks.
Init script exists? ... skipped (omnibus-gitlab has no init script)
Init script up-to-date? ... skipped (omnibus-gitlab has no init script)
projects have namespace: ... 
2/15 ... yes
[...]
7/242 ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.1.0 ? ... yes (2.3.3)
Your git bin path is "/opt/gitlab/embedded/bin/git"
Git version >= 2.7.3 ? ... yes (2.10.2)
Active users: 64

Checking GitLab ... Finished

Results of GitLab environment info

Here is the output for gitlab-rake gitlab:env:info:

System information
System:         Ubuntu 16.04
Current User:   git
Using RVM:      no
Ruby Version:   2.3.3p222
Gem Version:    2.6.6
Bundler Version:1.13.7
Rake Version:   10.5.0
Sidekiq Version:4.2.7

GitLab information
Version:        8.16.3
Revision:       d225908
Directory:      /opt/gitlab/embedded/service/gitlab-rails
DB Adapter:     postgresql
URL:            https://git.internal.getwellnetwork.com
HTTP Clone URL: https://git.internal.getwellnetwork.com/some-group/some-project.git
SSH Clone URL:  git@git.internal.getwellnetwork.com:some-group/some-project.git
Using LDAP:     yes
Using Omniauth: no

GitLab Shell
Version:        4.1.1
Repository storage paths:
- default:      /var/opt/gitlab/git-data/repositories
Hooks:          /opt/gitlab/embedded/service/gitlab-shell/hooks/
Git:            /opt/gitlab/embedded/bin/git

Possible fixes

I don't know Ruby well enough to know this is the fix, but by looking at other invocations of the failing method, I tried to apply the following change in my environment, and the import succeeded for me:

*** /opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/import.rake_orig 2017-01-31 09:51:43.651164440 -0500
--- /opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/import.rake      2017-01-31 09:52:06.723550204 -0500
***************
*** 63,69 ****
  
              if project.persisted?
                puts " * Created #{project.name} (#{repo_path})".color(:green)
!               ProjectCacheWorker.perform(project.id)
              else
                puts " * Failed trying to create #{project.name} (#{repo_path})".color(:red)
                puts "   Errors: #{project.errors.messages}".color(:red)
--- 63,69 ----
  
              if project.persisted?
                puts " * Created #{project.name} (#{repo_path})".color(:green)
!               ProjectCacheWorker.perform_async(project.id)
              else
                puts " * Failed trying to create #{project.name} (#{repo_path})".color(:red)
                puts "   Errors: #{project.errors.messages}".color(:red)