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
d6ac56e8
Commit
d6ac56e8
authored
Sep 21, 2021
by
Michał Zając
Committed by
Adam Hegyi
Sep 21, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reschedule pending RecalculateVulnerabilitiesOccurrencesUuid jobs
parent
c16e6b76
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
113 additions
and
0 deletions
+113
-0
db/post_migrate/20210918201050_remove_old_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb
..._jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb
+18
-0
db/post_migrate/20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb
..._jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb
+18
-0
db/schema_migrations/20210918201050
db/schema_migrations/20210918201050
+1
-0
db/schema_migrations/20210918202855
db/schema_migrations/20210918202855
+1
-0
spec/migrations/20210918201050_remove_old_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid_spec.rb
..._for_recalculate_vulnerabilities_occurrences_uuid_spec.rb
+45
-0
spec/migrations/20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid_spec.rb
..._for_recalculate_vulnerabilities_occurrences_uuid_spec.rb
+30
-0
No files found.
db/post_migrate/20210918201050_remove_old_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb
0 → 100644
View file @
d6ac56e8
# frozen_string_literal: true
class
RemoveOldPendingJobsForRecalculateVulnerabilitiesOccurrencesUuid
<
Gitlab
::
Database
::
Migration
[
1.0
]
MIGRATION_NAME
=
'RecalculateVulnerabilitiesOccurrencesUuid'
NEW_MIGRATION_START_DATE
=
DateTime
.
new
(
2021
,
8
,
18
,
0
,
0
,
0
)
def
up
Gitlab
::
Database
::
BackgroundMigrationJob
.
for_migration_class
(
MIGRATION_NAME
)
.
where
(
'created_at < ?'
,
NEW_MIGRATION_START_DATE
)
.
where
(
status: :pending
)
.
delete_all
end
def
down
# no-op
end
end
db/post_migrate/20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb
0 → 100644
View file @
d6ac56e8
# frozen_string_literal: true
class
ReschedulePendingJobsForRecalculateVulnerabilitiesOccurrencesUuid
<
Gitlab
::
Database
::
Migration
[
1.0
]
MIGRATION
=
"RecalculateVulnerabilitiesOccurrencesUuid"
DELAY_INTERVAL
=
2
.
minutes
disable_ddl_transaction!
def
up
delete_queued_jobs
(
MIGRATION
)
requeue_background_migration_jobs_by_range_at_intervals
(
MIGRATION
,
DELAY_INTERVAL
)
end
def
down
# no-op
end
end
db/schema_migrations/20210918201050
0 → 100644
View file @
d6ac56e8
596fd274ca1d0b2ce8698e048fea6080c9b777c48febb35a4917a6027826908e
\ No newline at end of file
db/schema_migrations/20210918202855
0 → 100644
View file @
d6ac56e8
a735ae13c13f5492a5c16d3e60884b60c44d1d57f6aaacaea13f3b1bf00a8d78
\ No newline at end of file
spec/migrations/20210918201050_remove_old_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid_spec.rb
0 → 100644
View file @
d6ac56e8
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20210918201050_remove_old_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb'
)
def
create_background_migration_jobs
(
ids
,
status
,
created_at
)
proper_status
=
case
status
when
:pending
Gitlab
::
Database
::
BackgroundMigrationJob
.
statuses
[
'pending'
]
when
:succeeded
Gitlab
::
Database
::
BackgroundMigrationJob
.
statuses
[
'succeeded'
]
else
raise
ArgumentError
end
background_migration_jobs
.
create!
(
class_name:
'RecalculateVulnerabilitiesOccurrencesUuid'
,
arguments:
Array
(
ids
),
status:
proper_status
,
created_at:
created_at
)
end
RSpec
.
describe
RemoveOldPendingJobsForRecalculateVulnerabilitiesOccurrencesUuid
,
:migration
do
let_it_be
(
:background_migration_jobs
)
{
table
(
:background_migration_jobs
)
}
let_it_be
(
:before_target_date
)
{
-
Float
::
INFINITY
..
(
DateTime
.
new
(
2021
,
8
,
17
,
23
,
59
,
59
))
}
let_it_be
(
:after_target_date
)
{
(
DateTime
.
new
(
2021
,
8
,
18
,
0
,
0
,
0
))
..
Float
::
INFINITY
}
context
'when old RecalculateVulnerabilitiesOccurrencesUuid jobs are pending'
do
before
do
create_background_migration_jobs
([
1
,
2
,
3
],
:succeeded
,
DateTime
.
new
(
2021
,
5
,
5
,
0
,
2
))
create_background_migration_jobs
([
4
,
5
,
6
],
:pending
,
DateTime
.
new
(
2021
,
5
,
5
,
0
,
4
))
create_background_migration_jobs
([
1
,
2
,
3
],
:succeeded
,
DateTime
.
new
(
2021
,
8
,
18
,
0
,
0
))
create_background_migration_jobs
([
4
,
5
,
6
],
:pending
,
DateTime
.
new
(
2021
,
8
,
18
,
0
,
2
))
create_background_migration_jobs
([
7
,
8
,
9
],
:pending
,
DateTime
.
new
(
2021
,
8
,
18
,
0
,
4
))
end
it
'removes old, pending jobs'
do
migrate!
expect
(
background_migration_jobs
.
where
(
created_at:
before_target_date
).
count
).
to
eq
(
1
)
expect
(
background_migration_jobs
.
where
(
created_at:
after_target_date
).
count
).
to
eq
(
3
)
end
end
end
spec/migrations/20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid_spec.rb
0 → 100644
View file @
d6ac56e8
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb'
)
RSpec
.
describe
ReschedulePendingJobsForRecalculateVulnerabilitiesOccurrencesUuid
,
:migration
do
let_it_be
(
:background_migration_jobs
)
{
table
(
:background_migration_jobs
)
}
context
'when RecalculateVulnerabilitiesOccurrencesUuid jobs are pending'
do
before
do
background_migration_jobs
.
create!
(
class_name:
'RecalculateVulnerabilitiesOccurrencesUuid'
,
arguments:
[
1
,
2
,
3
],
status:
Gitlab
::
Database
::
BackgroundMigrationJob
.
statuses
[
'pending'
]
)
background_migration_jobs
.
create!
(
class_name:
'RecalculateVulnerabilitiesOccurrencesUuid'
,
arguments:
[
4
,
5
,
6
],
status:
Gitlab
::
Database
::
BackgroundMigrationJob
.
statuses
[
'succeeded'
]
)
end
it
'queues pending jobs'
do
migrate!
expect
(
BackgroundMigrationWorker
.
jobs
.
length
).
to
eq
(
1
)
expect
(
BackgroundMigrationWorker
.
jobs
[
0
][
'args'
]).
to
eq
([
'RecalculateVulnerabilitiesOccurrencesUuid'
,
[
1
,
2
,
3
]])
expect
(
BackgroundMigrationWorker
.
jobs
[
0
][
'at'
]).
to
be_nil
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