-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAIN-T-98 Create a job to run indexing
- Loading branch information
1 parent
cff3cc0
commit a4e1d1a
Showing
7 changed files
with
14,981 additions
and
11,820 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
server/src/main/java/org/hkurh/doky/schedule/DocumentSolrIndexScheduledTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
server/src/main/java/org/hkurh/doky/schedule/db/ScheduledTaskEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
12 changes: 12 additions & 0 deletions
12
server/src/main/java/org/hkurh/doky/schedule/db/ScheduledTaskEntityRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
server/src/main/resources/db/migration/V13__add_scheduled_task.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |