fix(firstleg): execute carrier schedule due queries
This commit is contained in:
+4
-4
@@ -49,8 +49,8 @@ public interface CarrierScheduleQueryMapper extends BaseMapper<CarrierScheduleQu
|
||||
@Select("""
|
||||
SELECT * FROM fl_carrier_schedule_query
|
||||
WHERE status IN ('READY','MANUAL_REQUIRED')
|
||||
AND next_allowed_at IS NOT NULL AND next_allowed_at<=#{now}
|
||||
AND (lease_until IS NULL OR lease_until<#{now})
|
||||
AND next_allowed_at IS NOT NULL AND next_allowed_at <= #{now}
|
||||
AND (lease_until IS NULL OR lease_until < #{now})
|
||||
ORDER BY next_allowed_at,id LIMIT #{limit}
|
||||
""")
|
||||
List<CarrierScheduleQueryEntity> selectDue(@Param("now") LocalDateTime now, @Param("limit") int limit);
|
||||
@@ -59,8 +59,8 @@ public interface CarrierScheduleQueryMapper extends BaseMapper<CarrierScheduleQu
|
||||
UPDATE fl_carrier_schedule_query SET lease_owner=#{owner},lease_until=#{leaseUntil},
|
||||
updated_at=CURRENT_TIMESTAMP(3)
|
||||
WHERE id=#{id} AND status IN ('READY','MANUAL_REQUIRED')
|
||||
AND next_allowed_at IS NOT NULL AND next_allowed_at<=#{now}
|
||||
AND (lease_until IS NULL OR lease_until<#{now})
|
||||
AND next_allowed_at IS NOT NULL AND next_allowed_at <= #{now}
|
||||
AND (lease_until IS NULL OR lease_until < #{now})
|
||||
""")
|
||||
int claimLease(@Param("id") long id, @Param("owner") String owner,
|
||||
@Param("now") LocalDateTime now, @Param("leaseUntil") LocalDateTime leaseUntil);
|
||||
|
||||
+23
@@ -1,5 +1,8 @@
|
||||
package com.baiyue.firstleg.portschedule.repository;
|
||||
|
||||
import com.baiyue.firstleg.portschedule.mapper.CarrierScheduleQueryMapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
@@ -10,6 +13,26 @@ import java.nio.file.Path;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class CarrierScheduleQuerySqlContractTest {
|
||||
@Test
|
||||
void annotationSqlUsesExecutableComparisonOperators() throws Exception {
|
||||
String selectDue = String.join("\n", CarrierScheduleQueryMapper.class
|
||||
.getMethod("selectDue", java.time.LocalDateTime.class, int.class)
|
||||
.getAnnotation(Select.class).value());
|
||||
String claimLease = String.join("\n", CarrierScheduleQueryMapper.class
|
||||
.getMethod("claimLease", long.class, String.class, java.time.LocalDateTime.class,
|
||||
java.time.LocalDateTime.class)
|
||||
.getAnnotation(Update.class).value());
|
||||
|
||||
assertThat(selectDue)
|
||||
.contains("next_allowed_at <= #{now}")
|
||||
.contains("lease_until < #{now}")
|
||||
.doesNotContain("<");
|
||||
assertThat(claimLease)
|
||||
.contains("next_allowed_at <= #{now}")
|
||||
.contains("lease_until < #{now}")
|
||||
.doesNotContain("<");
|
||||
}
|
||||
|
||||
@Test
|
||||
void definesTaskAttemptsHistoryIdempotencyAndHardLimit() throws Exception {
|
||||
assertThat(moduleSql())
|
||||
|
||||
Reference in New Issue
Block a user