--- scheduler_service: добавление записи в launcher через новый сервис
This commit is contained in:
parent
d4767d5937
commit
55cd288dd9
1 changed files with 52 additions and 0 deletions
|
|
@ -0,0 +1,52 @@
|
||||||
|
package ru.spcex.clearing.scheduler.service;
|
||||||
|
|
||||||
|
import org.apache.kafka.clients.consumer.Consumer;
|
||||||
|
import org.apache.kafka.clients.producer.Producer;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import ru.clearing.classes.statics.data.scheduler.Launcher;
|
||||||
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.cud.schedule.LauncherCommandRequest;
|
||||||
|
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||||
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
public class LauncherService extends QueueConsumer implements InitializingBean {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
private final Imdg<Launcher> launcherMap;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public LauncherService(Consumer<String, Object> kafkaQueue, Producer<String, Object> kafkaProducer,
|
||||||
|
ImdgProvider imdgProvider) {
|
||||||
|
super(kafkaQueue, kafkaProducer);
|
||||||
|
this.launcherMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Launcher, Launcher.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet() {
|
||||||
|
callback(LauncherCommandRequest.class)
|
||||||
|
.setConsumer(this::newLauncher)
|
||||||
|
.forDestination(Consts.LAUNCHER_NEW, callbacks::put);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void newLauncher(BaseRequest<LauncherCommandRequest> userRequest) {
|
||||||
|
LauncherCommandRequest req = userRequest.getRequestPayload();
|
||||||
|
log.debug("LauncherCommandRequest received");
|
||||||
|
Instant created = Instant.now();
|
||||||
|
Launcher launcher = new Launcher();
|
||||||
|
launcher.setTask(req.getTaskName());
|
||||||
|
launcher.setSenderId(req.getUserId());
|
||||||
|
launcher.setCreated(created);
|
||||||
|
launcher.setUpdated(created);
|
||||||
|
launcherMap.insert(launcher);
|
||||||
|
log.debug("successfully processed, new id {}", launcher.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue