刘光辉
15 小时以前 34981c30a78e8bbd7791131059a9210f9928b62c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package jnpf.limsMapper;
 
import jnpf.base.mapper.SuperMapper;
import jnpf.limsEntity.LimsMessageDeliveryEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
 
import java.util.Date;
import java.util.List;
 
@Mapper
public interface LimsMessageDeliveryMapper extends SuperMapper<LimsMessageDeliveryEntity> {
    @Update("UPDATE lims_message_delivery SET status = 'SENDING', last_modify_time = CURRENT_TIMESTAMP " +
            "WHERE id = #{id} AND status IN ('PENDING', 'FAILED')")
    int claim(@Param("id") String id);
 
    @Select("SELECT * FROM lims_message_delivery " +
            "WHERE ((status = 'FAILED' AND (next_retry_time IS NULL OR next_retry_time <= CURRENT_TIMESTAMP)) " +
            "OR (status IN ('PENDING', 'SENDING') AND last_modify_time < #{staleBefore})) " +
            "AND retry_count < #{maxAttempts} ORDER BY last_modify_time, id LIMIT #{limit}")
    List<LimsMessageDeliveryEntity> selectRetryable(@Param("staleBefore") Date staleBefore,
                                                     @Param("limit") int limit,
                                                     @Param("maxAttempts") int maxAttempts);
 
    @Update("UPDATE lims_message_delivery SET status = 'SENDING', last_modify_time = CURRENT_TIMESTAMP " +
            "WHERE id = #{id} AND ((status = 'FAILED' AND (next_retry_time IS NULL OR next_retry_time <= CURRENT_TIMESTAMP)) " +
            "OR (status IN ('PENDING', 'SENDING') AND last_modify_time < #{staleBefore}))")
    int claimRetry(@Param("id") String id, @Param("staleBefore") Date staleBefore);
}