Skip to content

Commit

Permalink
MAIN-T-98 Create a job to run indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
hanna-eismant committed Apr 7, 2024
1 parent cff3cc0 commit a4e1d1a
Show file tree
Hide file tree
Showing 7 changed files with 14,981 additions and 11,820 deletions.
2 changes: 2 additions & 0 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ dependencies {
implementation 'com.azure:azure-storage-blob:12.25.2'
implementation 'org.apache.solr:solr-solrj:9.5.0'

// testImplementation 'org.awaitility:awaitility:4.2.0'

implementation 'net.logstash.logback:logstash-logback-encoder:7.4'

runtimeOnly 'org.springframework.boot:spring-boot-devtools'
Expand Down
26,699 changes: 14,879 additions & 11,820 deletions server/qodana.sarif.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions server/src/main/java/org/hkurh/doky/DokyApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.context.annotation.Bean
import org.springframework.scheduling.annotation.EnableScheduling
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import org.springframework.security.crypto.password.PasswordEncoder
import org.thymeleaf.spring6.SpringTemplateEngine
Expand All @@ -16,6 +17,7 @@ import org.thymeleaf.templateresolver.ITemplateResolver
import javax.crypto.spec.SecretKeySpec


@EnableScheduling
@SpringBootApplication
class DokyApplication {
@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.hkurh.doky.schedule

import org.apache.commons.logging.LogFactory
import org.hkurh.doky.schedule.db.ScheduledTaskEntityRepository
import org.hkurh.doky.search.DocumentIndexService
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
import java.util.*

@Component
class DocumentSolrIndexScheduledTask(
val documentIndexService: DocumentIndexService,
val scheduledTaskEntityRepository: ScheduledTaskEntityRepository
) {

private val taskName = "solr-index-documents"

@Scheduled(cron = "0 */10 * * * *")
// @Scheduled(cron = "0 0 3 * * SUN")
fun runFullIndex() {
LOG.info("Start full solr indexing for Documents")

// documentIndexService.fullIndex()

scheduledTaskEntityRepository.findByName(taskName)
.let {
it.modifiedDate = Date()
scheduledTaskEntityRepository.save(it)
}

LOG.info("Finish full solr indexing for Documents")
}

// @Scheduled(cron = "0 */2 * * * *")
// @Scheduled(cron = "0 0 3 * * MON-SAT")
fun runUpdateIndex() {
val taskName = "solr-update-index-documents"
LOG.info("RUN UPDATE INDEX")
}

companion object {
private val LOG = LogFactory.getLog(DocumentSolrIndexScheduledTask::class.java)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.hkurh.doky.schedule.db

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EntityListeners
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.Table
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import org.springframework.lang.NonNull
import java.util.*

@Entity
@Table(name = "scheduled_task")
class ScheduledTaskEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
var id: Long = -1

@Column(name = "name", nullable = false, unique = true)
var name: String = ""

@Column(name = "last_run_date")
var modifiedDate: Date? = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.hkurh.doky.schedule.db;

import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.JpaSpecificationExecutor

interface ScheduledTaskEntityRepository : JpaRepository<ScheduledTaskEntity, Long>,
JpaSpecificationExecutor<ScheduledTaskEntity> {


fun findByName(name: String): ScheduledTaskEntity

}
12 changes: 12 additions & 0 deletions server/src/main/resources/db/migration/V13__add_scheduled_task.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE TABLE scheduled_task
(
id BIGINT AUTO_INCREMENT NOT NULL,
name VARCHAR(255) NOT NULL,
last_run_date datetime NULL,
CONSTRAINT pk_scheduled_task PRIMARY KEY (id)
);

ALTER TABLE scheduled_task
ADD CONSTRAINT uc_scheduled_task_name UNIQUE (name);

-- INSERT INTO scheduled_task (name) VALUES ("solr-index-documents");

0 comments on commit a4e1d1a

Please sign in to comment.