Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
915f2a9c
Commit
915f2a9c
authored
Feb 18, 2021
by
ggelatti
Committed by
Steve Abrams
Mar 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Composer cache update worker
Updates composer cache upon package creation and deletion.
parent
9a0212d1
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
122 additions
and
0 deletions
+122
-0
app/models/packages/package.rb
app/models/packages/package.rb
+8
-0
app/services/packages/composer/create_package_service.rb
app/services/packages/composer/create_package_service.rb
+2
-0
app/workers/all_queues.yml
app/workers/all_queues.yml
+8
-0
app/workers/packages/composer/cache_update_worker.rb
app/workers/packages/composer/cache_update_worker.rb
+23
-0
changelogs/unreleased/290288-composer-cache-hooks.yml
changelogs/unreleased/290288-composer-cache-hooks.yml
+5
-0
config/sidekiq_queues.yml
config/sidekiq_queues.yml
+2
-0
spec/models/packages/package_spec.rb
spec/models/packages/package_spec.rb
+18
-0
spec/services/packages/composer/create_package_service_spec.rb
...services/packages/composer/create_package_service_spec.rb
+8
-0
spec/workers/packages/composer/cache_update_worker_spec.rb
spec/workers/packages/composer/cache_update_worker_spec.rb
+48
-0
No files found.
app/models/packages/package.rb
View file @
915f2a9c
...
...
@@ -132,6 +132,8 @@ class Packages::Package < ApplicationRecord
scope
:order_project_path_desc
,
->
{
joins
(
:project
).
reorder
(
'projects.path DESC, id DESC'
)
}
scope
:order_by_package_file
,
->
{
joins
(
:package_files
).
order
(
'packages_package_files.created_at ASC'
)
}
after_commit
:update_composer_cache
,
on: :destroy
,
if:
->
{
composer?
}
def
self
.
for_projects
(
projects
)
return
none
unless
projects
.
any?
...
...
@@ -232,6 +234,12 @@ class Packages::Package < ApplicationRecord
private
def
update_composer_cache
return
unless
composer?
::
Packages
::
Composer
::
CacheUpdateWorker
.
perform_async
(
project_id
,
name
,
composer_metadatum
.
version_cache_sha
)
# rubocop:disable CodeReuse/Worker
end
def
composer_tag_version?
composer?
&&
!
Gitlab
::
Regex
.
composer_dev_version_regex
.
match
(
version
.
to_s
)
end
...
...
app/services/packages/composer/create_package_service.rb
View file @
915f2a9c
...
...
@@ -17,6 +17,8 @@ module Packages
})
end
::
Packages
::
Composer
::
CacheUpdateWorker
.
perform_async
(
created_package
.
project_id
,
created_package
.
name
,
nil
)
created_package
end
...
...
app/workers/all_queues.yml
View file @
915f2a9c
...
...
@@ -1908,6 +1908,14 @@
:weight:
2
:idempotent:
:tags: []
-
:name: packages_composer_cache_update
:feature_category: :package_registry
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight:
1
:idempotent:
true
:tags: []
-
:name: pages
:feature_category: :pages
:has_external_dependencies:
...
...
app/workers/packages/composer/cache_update_worker.rb
0 → 100644
View file @
915f2a9c
# frozen_string_literal: true
module
Packages
module
Composer
class
CacheUpdateWorker
include
ApplicationWorker
feature_category
:package_registry
idempotent!
def
perform
(
project_id
,
package_name
,
last_page_sha
)
project
=
Project
.
find_by_id
(
project_id
)
return
unless
project
Gitlab
::
Composer
::
Cache
.
new
(
project:
project
,
name:
package_name
,
last_page_sha:
last_page_sha
).
execute
rescue
=>
e
Gitlab
::
ErrorTracking
.
log_exception
(
e
,
project_id:
project_id
)
end
end
end
end
changelogs/unreleased/290288-composer-cache-hooks.yml
0 → 100644
View file @
915f2a9c
---
title
:
Composer cache update worker
merge_request
:
54551
author
:
type
:
other
config/sidekiq_queues.yml
View file @
915f2a9c
...
...
@@ -240,6 +240,8 @@
-
1
-
-
package_repositories
-
1
-
-
packages_composer_cache_update
-
1
-
-
pages
-
1
-
-
pages_domain_ssl_renewal
...
...
spec/models/packages/package_spec.rb
View file @
915f2a9c
...
...
@@ -854,4 +854,22 @@ RSpec.describe Packages::Package, type: :model do
it_behaves_like
'not enqueuing a sync worker job'
end
end
context
'destroying a composer package'
do
let_it_be
(
:package_name
)
{
'composer-package-name'
}
let_it_be
(
:json
)
{
{
'name'
=>
package_name
}
}
let_it_be
(
:project
)
{
create
(
:project
,
:custom_repo
,
files:
{
'composer.json'
=>
json
.
to_json
}
)
}
let!
(
:package
)
{
create
(
:composer_package
,
:with_metadatum
,
project:
project
,
name:
package_name
,
version:
'1.0.0'
,
json:
json
)
}
before
do
Gitlab
::
Composer
::
Cache
.
new
(
project:
project
,
name:
package_name
).
execute
package
.
composer_metadatum
.
reload
end
it
'schedule the update job'
do
expect
(
::
Packages
::
Composer
::
CacheUpdateWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
package_name
,
package
.
composer_metadatum
.
version_cache_sha
)
package
.
destroy!
end
end
end
spec/services/packages/composer/create_package_service_spec.rb
View file @
915f2a9c
...
...
@@ -28,6 +28,8 @@ RSpec.describe Packages::Composer::CreatePackageService do
let
(
:branch
)
{
project
.
repository
.
find_branch
(
'master'
)
}
it
'creates the package'
do
expect
(
::
Packages
::
Composer
::
CacheUpdateWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
package_name
,
nil
)
expect
{
subject
}
.
to
change
{
Packages
::
Package
.
composer
.
count
}.
by
(
1
)
.
and
change
{
Packages
::
Composer
::
Metadatum
.
count
}.
by
(
1
)
...
...
@@ -54,6 +56,8 @@ RSpec.describe Packages::Composer::CreatePackageService do
end
it
'creates the package'
do
expect
(
::
Packages
::
Composer
::
CacheUpdateWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
package_name
,
nil
)
expect
{
subject
}
.
to
change
{
Packages
::
Package
.
composer
.
count
}.
by
(
1
)
.
and
change
{
Packages
::
Composer
::
Metadatum
.
count
}.
by
(
1
)
...
...
@@ -80,6 +84,8 @@ RSpec.describe Packages::Composer::CreatePackageService do
end
it
'does not create a new package'
do
expect
(
::
Packages
::
Composer
::
CacheUpdateWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
package_name
,
nil
)
expect
{
subject
}
.
to
change
{
Packages
::
Package
.
composer
.
count
}.
by
(
0
)
.
and
change
{
Packages
::
Composer
::
Metadatum
.
count
}.
by
(
0
)
...
...
@@ -101,6 +107,8 @@ RSpec.describe Packages::Composer::CreatePackageService do
let!
(
:other_package
)
{
create
(
:package
,
name:
package_name
,
version:
'dev-master'
,
project:
other_project
)
}
it
'creates the package'
do
expect
(
::
Packages
::
Composer
::
CacheUpdateWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
package_name
,
nil
)
expect
{
subject
}
.
to
change
{
Packages
::
Package
.
composer
.
count
}.
by
(
1
)
.
and
change
{
Packages
::
Composer
::
Metadatum
.
count
}.
by
(
1
)
...
...
spec/workers/packages/composer/cache_update_worker_spec.rb
0 → 100644
View file @
915f2a9c
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Packages
::
Composer
::
CacheUpdateWorker
,
type: :worker
do
describe
'#perform'
do
let_it_be
(
:package_name
)
{
'sample-project'
}
let_it_be
(
:json
)
{
{
'name'
=>
package_name
}
}
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:custom_repo
,
files:
{
'composer.json'
=>
json
.
to_json
},
group:
group
)
}
let
(
:last_sha
)
{
nil
}
let!
(
:package
)
{
create
(
:composer_package
,
:with_metadatum
,
project:
project
,
name:
package_name
,
version:
'1.0.0'
,
json:
json
)
}
let
(
:job_args
)
{
[
project
.
id
,
package_name
,
last_sha
]
}
subject
{
described_class
.
new
.
perform
(
*
job_args
)
}
before
do
stub_composer_cache_object_storage
end
include_examples
'an idempotent worker'
do
context
'creating a package'
do
it
'updates the cache'
do
expect
{
subject
}.
to
change
{
Packages
::
Composer
::
CacheFile
.
count
}.
by
(
1
)
end
end
context
'deleting a package'
do
let!
(
:last_sha
)
do
Gitlab
::
Composer
::
Cache
.
new
(
project:
project
,
name:
package_name
).
execute
package
.
reload
.
composer_metadatum
.
version_cache_sha
end
before
do
package
.
destroy!
end
it
'marks the file for deletion'
do
expect
{
subject
}.
not_to
change
{
Packages
::
Composer
::
CacheFile
.
count
}
cache_file
=
Packages
::
Composer
::
CacheFile
.
last
expect
(
cache_file
.
reload
.
delete_at
).
not_to
be_nil
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment