package com.docus.server.collect.web.job;

import com.docus.server.archivefile.service.ITaskMessageService;
import com.docus.server.archivefile.service.impl.TrackRetryService;
import com.docus.server.entity.TaskMessage;
import com.docus.server.enums.StateEnum;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 重试所有被动消息 job
 */
@Component
@Slf4j
public class TrackRetryJob {

    @Resource
    private ITaskMessageService messageService;
    @Resource
    private TrackRetryService trackRetryService;

    @XxlJob("trackRetryJob")
    public void retry() throws Exception {
        List<TaskMessage> messages = messageService.findByState(StateEnum.FAIL);

        for (TaskMessage message : messages) {
            trackRetryService.doRetryTaskMessage(message);
        }
    }


}
