package com.css.simulation.resource.scheduler.adapter.controller;


import com.css.simulation.resource.scheduler.app.service.TaskApplicationService;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RefreshScope
@RestController
@RequestMapping("/task")
public class TaskController {

    @Resource
    private TaskApplicationService taskApplicationService;
    //* -------------------------------- Comment --------------------------------

    /**
     * 任务执行前调用该接口，确定该任务没有被终止
     */
    @GetMapping("/confirm")
    public Boolean confirm(@RequestParam("taskId") String taskId) {
        return taskApplicationService.confirm(taskId);
    }

    // -------------------------------- Comment --------------------------------

    /**
     * Pod 的心跳接口
     */
    @GetMapping("/tick")
    public void tick(@RequestParam("taskId") String taskId) {
        taskApplicationService.tick(taskId);
    }
    //* -------------------------------- Comment --------------------------------

    /**
     * 修改任务状态
     */
    @GetMapping("/state")
    public void state(@RequestParam("taskId") String taskId, @RequestParam("state") String state, @RequestParam("podName") String podName) {
        taskApplicationService.state(taskId, state, podName);
    }


}
