Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions blibli-backend-framework-job/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>blibli-backend-framework</artifactId>
<groupId>com.blibli.oss</groupId>
<version>0.0.6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>blibli-backend-framework-job</artifactId>

<dependencies>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.blibli.oss</groupId>
<artifactId>blibli-backend-framework-reactor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.blibli.oss.backend.job;

import reactor.core.publisher.Mono;

public interface Job<T> {

Mono<Void> execute(T request);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.blibli.oss.backend.job;

import reactor.core.publisher.Mono;

public interface JobManager {

Mono<Void> execute(String command);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.blibli.oss.backend.job;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.cli.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;

@Slf4j
class JobTest {

private ObjectMapper objectMapper;

@BeforeEach
void setUp() {
objectMapper = new ObjectMapper();
}

@Test
void testFirst() {
String[] arguments = "reindex --start=100 --from=200".split("\\s+");

String command = arguments[0];
Map<String, String> map = new HashMap<>();

for (int i = 1; i < arguments.length; i++) {
String[] split = arguments[i].split("=");
if (split.length == 2 && split[0].startsWith("--")) {
map.put(split[0].substring(2), split[1]);
}
}

Request request = objectMapper.convertValue(map, Request.class);
log.info(request.toString());
}

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class Request {

private Integer start;

private Integer from;

}
}
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<module>blibli-backend-framework-validation</module>
<module>blibli-backend-framework-sleuth</module>
<module>blibli-backend-framework-external-api</module>
<module>blibli-backend-framework-job</module>
</modules>

<parent>
Expand Down Expand Up @@ -114,6 +115,11 @@
<artifactId>blibli-backend-framework-version</artifactId>
<version>${blibli-framework.version}</version>
</dependency>
<dependency>
<groupId>com.blibli.oss</groupId>
<artifactId>blibli-backend-framework-job</artifactId>
<version>${blibli-framework.version}</version>
</dependency>
<dependency>
<groupId>com.blibli.oss</groupId>
<artifactId>blibli-backend-framework-json</artifactId>
Expand Down