<|start_filename|>api-gateway/src/main/java/cn/cib/configuration/service/Impl/VersionServiceImpl.java<|end_filename|>
package cn.cib.configuration.service.Impl;

import ch.qos.logback.core.util.TimeUtil;
import cn.cib.configuration.service.VersionService;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.Calendar;
import java.util.Timer;
import java.util.concurrent.*;

/**
 * @author clyde lou
 */
@Service
public class VersionServiceImpl implements VersionService {
    private ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);

    @Override
    public String version() {
        return String.format("%s %s", "1.0.0", TimeUnit.NANOSECONDS);
    }

    @PostConstruct
    public void init() {
        Runnable task = () -> {
            try {
                TimeUnit.SECONDS.sleep(2);
                System.out.println("Scheduling: " + System.nanoTime());
            } catch (InterruptedException e) {
                System.err.println("task interrupted");
            }
        };

        executor.scheduleWithFixedDelay(task, 0, 1, TimeUnit.SECONDS);
    }

    @PreDestroy
    public void shutdown() {
        System.out.println("***service shutdown***");
        executor.shutdown();
    }
}


<|start_filename|>api-gateway/src/main/java/cn/cib/configuration/controller/Api.java<|end_filename|>
package cn.cib.configuration.controller;

import cn.cib.configuration.service.VersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author clyde lou
 */
@RestController
public class Api {
    @Autowired
    private VersionService versionService;

    @GetMapping("v")
    public String version() {
        return versionService.version();
    }
}


<|start_filename|>spring-batch/src/main/java/cn/Application.java<|end_filename|>
package cn;

import cn.cib.service.JobLaunchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

import javax.annotation.PostConstruct;

@SpringBootApplication
@EnableBatchProcessing
@Slf4j
@ComponentScan()
public class Application {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }

    @Autowired
    private JobLaunchService jobLaunchService;

    @Autowired
    private Job jobWithRepositoryStep;

    @PostConstruct
    public void runJob(){
        log.info("run job from scheduler");
        jobLaunchService.launchJob(jobWithRepositoryStep);
    }
}


<|start_filename|>api-gateway/src/main/java/cn/cib/configuration/service/VersionService.java<|end_filename|>
package cn.cib.configuration.service;

/**
 * @author clyde lou
 */
public interface VersionService {
    String version();
}
