Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit c5015ee

Browse files
committed
Start to hook together all indexing
1 parent 4bc12c2 commit c5015ee

File tree

3 files changed

+73
-59
lines changed

3 files changed

+73
-59
lines changed
Lines changed: 68 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,68 @@
1-
package com.searchcode.app.jobs.enqueue;
2-
3-
import com.searchcode.app.dao.IRepo;
4-
import com.searchcode.app.service.Singleton;
5-
import com.searchcode.app.service.index.IIndexService;
6-
import com.searchcode.app.util.Helpers;
7-
import com.searchcode.app.util.LoggerWrapper;
8-
import org.quartz.DisallowConcurrentExecution;
9-
import org.quartz.Job;
10-
import org.quartz.JobExecutionContext;
11-
import org.quartz.PersistJobDataAfterExecution;
12-
13-
/**
14-
* Responsible for adding all of the repositories inside the database into the queues. There will be a queue
15-
* for GIT and SVN or any other repository added.
16-
* TODO add logic to test that the right queue has things added to it
17-
*/
18-
@PersistJobDataAfterExecution
19-
@DisallowConcurrentExecution
20-
public class EnqueueSearchcodeRepositoryJob implements Job {
21-
private final IIndexService indexService;
22-
private final LoggerWrapper logger;
23-
private final IRepo repo;
24-
private final Helpers helpers;
25-
26-
public EnqueueSearchcodeRepositoryJob() {
27-
this.indexService = Singleton.getIndexService();
28-
this.repo = Singleton.getRepo();
29-
this.logger = Singleton.getLogger();
30-
this.helpers = Singleton.getHelpers();
31-
}
32-
33-
public void execute(JobExecutionContext context) {
34-
this.logger.info("fe39b962::starting enqueue job");
35-
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
36-
37-
// TODO this never returns false, should probably implement back-pressure
38-
if (this.indexService.shouldPause(IIndexService.JobType.REPO_ADDER)) {
39-
return;
40-
}
41-
42-
try {
43-
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
44-
45-
var repoGitQueue = Singleton.getUniqueGitRepoQueue();
46-
var repoSvnQueue = Singleton.getUniqueSvnRepoQueue();
47-
48-
// Determine where we have started from a repo collection
49-
// determine where that ends
50-
// update the point
51-
// Get the batch of repositories from the database
52-
// add them to the queue
53-
} catch (Exception ex) {
54-
this.logger.severe(String.format("8675db36::error in class %s exception %s", ex.getClass(), ex.getMessage()));
55-
}
56-
}
57-
}
1+
package com.searchcode.app.jobs.enqueue;
2+
3+
import com.searchcode.app.dao.Data;
4+
import com.searchcode.app.dao.IRepo;
5+
import com.searchcode.app.service.Singleton;
6+
import com.searchcode.app.service.index.IIndexService;
7+
import com.searchcode.app.util.Helpers;
8+
import com.searchcode.app.util.LoggerWrapper;
9+
import org.quartz.DisallowConcurrentExecution;
10+
import org.quartz.Job;
11+
import org.quartz.JobExecutionContext;
12+
import org.quartz.PersistJobDataAfterExecution;
13+
14+
/**
15+
* Responsible for adding all of the repositories inside the database into the queues. There will be a queue
16+
* for GIT and SVN or any other repository added.
17+
* TODO add logic to test that the right queue has things added to it
18+
*/
19+
@PersistJobDataAfterExecution
20+
@DisallowConcurrentExecution
21+
public class EnqueueSearchcodeRepositoryJob implements Job {
22+
private final IIndexService indexService;
23+
private final LoggerWrapper logger;
24+
private final IRepo repo;
25+
private final Helpers helpers;
26+
private final Data data;
27+
28+
public EnqueueSearchcodeRepositoryJob() {
29+
this.indexService = Singleton.getIndexService();
30+
this.repo = Singleton.getRepo();
31+
this.logger = Singleton.getLogger();
32+
this.helpers = Singleton.getHelpers();
33+
this.data = Singleton.getData();
34+
}
35+
36+
public void execute(JobExecutionContext context) {
37+
this.logger.info("fe39b962::starting enqueue job");
38+
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
39+
40+
// TODO this never returns false, should probably implement back-pressure
41+
if (this.indexService.shouldPause(IIndexService.JobType.REPO_ADDER)) {
42+
return;
43+
}
44+
45+
try {
46+
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
47+
48+
var repoGitQueue = Singleton.getUniqueGitRepoQueue();
49+
var repoSvnQueue = Singleton.getUniqueSvnRepoQueue();
50+
51+
// this.repo.getAllRepo();
52+
53+
// for (var r : this.repo.getAllRepo()) {
54+
// repoGitQueue.add(r);
55+
// }
56+
57+
repoGitQueue.add(this.repo.getRepoById(1).get());
58+
59+
// Determine where we have started from a repo collection
60+
// determine where that ends
61+
// update the point
62+
// Get the batch of repositories from the database
63+
// add them to the queue
64+
} catch (Exception ex) {
65+
this.logger.severe(String.format("8675db36::error in class %s exception %s", ex.getClass(), ex.getMessage()));
66+
}
67+
}
68+
}

src/main/java/com/searchcode/app/jobs/searchcode/ReindexerJob.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public void execute(JobExecutionContext context) {
5353
try {
5454
while (true) {
5555
// Sleep for a jitter time to avoid many indexers converging on the same schedule
56-
Thread.sleep(this.INDEXTIME * this.helpers.getRandomJitterSleepTimeMilliseconds());
56+
var sleepTime = this.helpers.getRandomJitterSleepTimeMilliseconds();
57+
this.logger.info(String.format("6d380ec6::reindexer sleep time %d", sleepTime));
58+
Thread.sleep(sleepTime);
5759

5860
var codeIndexQueueSize = this.indexQueue.size();
5961

src/main/java/com/searchcode/app/service/JobService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public JobService() {
8585
* Starts all of the above jobs as per their unique requirements between searchcode.com
8686
* and local runner
8787
*/
88-
public void initialJobs() {
88+
public synchronized void initialJobs() {
8989
// Having this run multiple times can be an issue so ensure it can not happen
9090
if (this.initialJobsRun) {
9191
return;
@@ -102,6 +102,7 @@ public void initialJobs() {
102102
// searchcode.com path
103103
this.startHighlighter();
104104
this.startReIndexer();
105+
this.startRepositoryJobs();
105106
this.startSearchcodeEnqueueJob();
106107
}
107108

0 commit comments

Comments
 (0)