Skip to content

Commit 83f00ca

Browse files
authored
Merge pull request #1151 from amvanbaren/delete-file-resource-jobs
Remove jobs for file resources that still exist
2 parents 6afcf79 + d43b199 commit 83f00ca

File tree

13 files changed

+144
-130
lines changed

13 files changed

+144
-130
lines changed

server/src/main/java/org/eclipse/openvsx/entities/MigrationItem.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class MigrationItem {
2525

2626
private String jobName;
2727

28+
public void setId(long id) {
29+
this.id = id;
30+
}
31+
2832
public long getId() {
2933
return id;
3034
}

server/src/main/java/org/eclipse/openvsx/migration/MigrationItemJobRequestHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public void run(HandlerJobRequest<?> jobRequest) throws Exception {
5858
for(var item : items) {
5959
migrations.enqueueMigration(item);
6060
}
61+
62+
logger.info("Scheduled migration items: {}", items.getSize());
6163
if(!items.hasNext()) {
6264
scheduler.deleteRecurringJob(getJobName());
6365
}

server/src/main/java/org/eclipse/openvsx/migration/MigrationService.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import org.jobrunr.storage.JobNotFoundException;
2626
import org.slf4j.Logger;
2727
import org.slf4j.LoggerFactory;
28-
import org.springframework.data.domain.PageRequest;
29-
import org.springframework.data.domain.Pageable;
3028
import org.springframework.retry.annotation.Retryable;
3129
import org.springframework.scheduling.annotation.Async;
3230
import org.springframework.stereotype.Component;
@@ -135,15 +133,19 @@ public FileResource getDownload(ExtensionVersion extVersion) {
135133

136134
@Async
137135
public void clearJobQueue() {
138-
// TODO remove after deployment of v0.23.4
139-
Pageable page = PageRequest.ofSize(10000);
140-
while(page != null) {
141-
var migrationItems = repositories.findMigrationItemsByJobName("RemoveFileResourceTypeResourceMigration", page);
136+
// TODO remove after deployment of v0.23.5
137+
var offset = 0;
138+
var limit = 10000;
139+
var hasNext = true;
140+
var counter = 0;
141+
while(hasNext) {
142+
var migrationItems = repositories.findRemoveFileResourceTypeResourceMigrationItems(offset, limit);
142143
for (var item : migrationItems) {
143144
var jobIdText = item.getJobName() + "::itemId=" + item.getId();
144145
var jobId = UUID.nameUUIDFromBytes(jobIdText.getBytes(StandardCharsets.UTF_8));
145146
try {
146147
scheduler.delete(jobId);
148+
counter++;
147149
} catch (JobNotFoundException | IllegalJobStateChangeException | ConcurrentJobModificationException e) {
148150
var suppressException = e instanceof JobNotFoundException || (e instanceof IllegalJobStateChangeException && e.getMessage().endsWith("from DELETED to DELETED."));
149151
if(!suppressException) {
@@ -152,7 +154,9 @@ public void clearJobQueue() {
152154
}
153155
}
154156

155-
page = migrationItems.hasNext() ? migrationItems.getPageable().next() : null;
157+
logger.info("Total deleted jobs: {}/{}", counter, offset + limit);
158+
offset += limit;
159+
hasNext = migrationItems.size() == limit;
156160
}
157161
}
158162
}

server/src/main/java/org/eclipse/openvsx/migration/ScheduleMigrationsListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public ScheduleMigrationsListener(JobRequestScheduler scheduler, MigrationServic
4242

4343
@EventListener
4444
public void applicationStarted(ApplicationStartedEvent event) {
45-
// TODO remove after deployment of v0.23.4
45+
// TODO remove after deployment of v0.23.5
4646
migrations.clearJobQueue();
4747

4848
var instant = Instant.now().plusSeconds(delay);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/** ******************************************************************************
2+
* Copyright (c) 2025 Precies. Software OU and others
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
* ****************************************************************************** */
10+
package org.eclipse.openvsx.repositories;
11+
12+
import org.eclipse.openvsx.entities.MigrationItem;
13+
import org.jooq.DSLContext;
14+
import org.springframework.stereotype.Component;
15+
16+
import java.util.List;
17+
18+
import static org.eclipse.openvsx.jooq.Tables.FILE_RESOURCE;
19+
import static org.eclipse.openvsx.jooq.Tables.MIGRATION_ITEM;
20+
21+
@Component
22+
public class MigrationItemJooqRepository {
23+
24+
private final DSLContext dsl;
25+
26+
public MigrationItemJooqRepository(DSLContext dsl) {
27+
this.dsl = dsl;
28+
}
29+
30+
public List<MigrationItem> findRemoveFileResourceTypeResourceMigrationItems(int offset, int limit) {
31+
var jobName = "RemoveFileResourceTypeResourceMigration";
32+
return dsl.select(MIGRATION_ITEM.ID)
33+
.from(MIGRATION_ITEM)
34+
.join(FILE_RESOURCE).on(FILE_RESOURCE.ID.eq(MIGRATION_ITEM.ENTITY_ID))
35+
.where(MIGRATION_ITEM.JOB_NAME.eq(jobName))
36+
.limit(limit)
37+
.offset(offset)
38+
.fetch(row -> {
39+
var item = new MigrationItem();
40+
item.setJobName(jobName);
41+
item.setId(row.get(MIGRATION_ITEM.ID));
42+
return item;
43+
});
44+
}
45+
}

server/src/main/java/org/eclipse/openvsx/repositories/RepositoryService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class RepositoryService {
5656
private final AdminStatisticsRepository adminStatisticsRepo;
5757
private final AdminStatisticCalculationsRepository adminStatisticCalculationsRepo;
5858
private final MigrationItemRepository migrationItemRepo;
59+
private final MigrationItemJooqRepository migrationItemJooqRepo;
5960
private final SignatureKeyPairRepository signatureKeyPairRepo;
6061
private final SignatureKeyPairJooqRepository signatureKeyPairJooqRepo;
6162

@@ -80,6 +81,7 @@ public RepositoryService(
8081
AdminStatisticsRepository adminStatisticsRepo,
8182
AdminStatisticCalculationsRepository adminStatisticCalculationsRepo,
8283
MigrationItemRepository migrationItemRepo,
84+
MigrationItemJooqRepository migrationItemJooqRepo,
8385
SignatureKeyPairRepository signatureKeyPairRepo,
8486
SignatureKeyPairJooqRepository signatureKeyPairJooqRepo
8587
) {
@@ -103,6 +105,7 @@ public RepositoryService(
103105
this.adminStatisticsRepo = adminStatisticsRepo;
104106
this.adminStatisticCalculationsRepo = adminStatisticCalculationsRepo;
105107
this.migrationItemRepo = migrationItemRepo;
108+
this.migrationItemJooqRepo = migrationItemJooqRepo;
106109
this.signatureKeyPairRepo = signatureKeyPairRepo;
107110
this.signatureKeyPairJooqRepo = signatureKeyPairJooqRepo;
108111
}
@@ -632,7 +635,7 @@ public Streamable<Extension> findDeprecatedExtensions(Extension replacement) {
632635
return extensionRepo.findByReplacement(replacement);
633636
}
634637

635-
public Slice<MigrationItem> findMigrationItemsByJobName(String jobName, Pageable page) {
636-
return migrationItemRepo.findByJobName(jobName, page);
638+
public List<MigrationItem> findRemoveFileResourceTypeResourceMigrationItems(int offset, int limit) {
639+
return migrationItemJooqRepo.findRemoveFileResourceTypeResourceMigrationItems(offset, limit);
637640
}
638641
}

server/src/main/jooq-gen/org/eclipse/openvsx/jooq/tables/ExtensionVersion.java

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/main/jooq-gen/org/eclipse/openvsx/jooq/tables/MigrationItem.java

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/main/jooq-gen/org/eclipse/openvsx/jooq/tables/UserData.java

Lines changed: 7 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/main/jooq-gen/org/eclipse/openvsx/jooq/tables/records/ExtensionVersionRecord.java

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)