package demo.simple.queue.controller;

import com.github.microservice.components.data.mongo.queue.service.ExecQueueService;
import com.github.microservice.core.helper.ApplicationContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.UUID;

@RequestMapping("queue")
@RestController
@Slf4j
public class QueueController {

    @Autowired
    private ExecQueueService execQueueService;



    @RequestMapping("add")
    public Object add() {

        return execQueueService.add(Map.of("x", UUID.randomUUID()), 10, (data) -> {
            final ExecQueueService execQueueService =    ApplicationContextHolder.getContext().getBean(ExecQueueService.class);
            log.info("execute : {} -> {} -> {}", Thread.currentThread().getName(), data, execQueueService);
            return false;
        });
    }


}
