@@ -80,6 +80,10 @@ public class CeQueueDao implements Dao { | |||
return Optional.fromNullable(mapper(session).selectByUuid(uuid)); | |||
} | |||
public List<CeQueueDto> selectPendingByMinimumExecutionCount(DbSession dbSession, int minExecutionCount) { | |||
return mapper(dbSession).selectPendingByMinimumExecutionCount(minExecutionCount); | |||
} | |||
public CeQueueDto insert(DbSession session, CeQueueDto dto) { | |||
if (dto.getCreatedAt() == 0L || dto.getUpdatedAt() == 0L) { | |||
long now = system2.now(); |
@@ -41,6 +41,11 @@ public interface CeQueueMapper { | |||
@CheckForNull | |||
CeQueueDto selectByUuid(@Param("uuid") String uuid); | |||
/** | |||
* Select all pending tasks which execution count is greater than or equal to the specified {@code minExecutionCount}. | |||
*/ | |||
List<CeQueueDto> selectPendingByMinimumExecutionCount(@Param("minExecutionCount") int minExecutionCount); | |||
int countByStatusAndComponentUuid(@Param("status") CeQueueDto.Status status, @Nullable @Param("componentUuid") String componentUuid); | |||
void insert(CeQueueDto dto); | |||
@@ -52,5 +57,4 @@ public interface CeQueueMapper { | |||
@Param("old") UpdateIf.OldProperties oldProperties); | |||
void deleteByUuid(@Param("uuid") String uuid); | |||
} |
@@ -175,6 +175,16 @@ | |||
id asc | |||
</sql> | |||
<select id="selectPendingByMinimumExecutionCount" resultType="org.sonar.db.ce.CeQueueDto"> | |||
select | |||
<include refid="columns"/> | |||
from | |||
ce_queue cq | |||
where | |||
cq.status = 'PENDING' | |||
and cq.execution_count >= #{minExecutionCount,jdbcType=INTEGER} | |||
</select> | |||
<insert id="insert" parameterType="org.sonar.db.ce.CeQueueDto" useGeneratedKeys="false"> | |||
insert into ce_queue | |||
( |
@@ -159,6 +159,35 @@ public class CeQueueDaoTest { | |||
assertThat(underTest.selectAllInAscOrder(db.getSession())).extracting("uuid").containsOnly(TASK_UUID_1, TASK_UUID_2, TASK_UUID_3); | |||
} | |||
@Test | |||
public void selectPendingByMinimumExecutionCount_returns_pending_tasks_with_executionCount_greater_or_equal_to_argument() { | |||
insert("p1", CeQueueDto.Status.PENDING, 0); | |||
insert("p2", CeQueueDto.Status.PENDING, 1); | |||
insert("p3", CeQueueDto.Status.PENDING, 2); | |||
insert("i1", CeQueueDto.Status.IN_PROGRESS, 0); | |||
insert("i2", CeQueueDto.Status.IN_PROGRESS, 1); | |||
insert("i3", CeQueueDto.Status.IN_PROGRESS, 2); | |||
assertThat(underTest.selectPendingByMinimumExecutionCount(db.getSession(), 0)) | |||
.extracting(CeQueueDto::getUuid) | |||
.containsOnly("p1", "p2", "p3"); | |||
assertThat(underTest.selectPendingByMinimumExecutionCount(db.getSession(), 1)) | |||
.extracting(CeQueueDto::getUuid) | |||
.containsOnly("p2", "p3"); | |||
assertThat(underTest.selectPendingByMinimumExecutionCount(db.getSession(), 2)) | |||
.extracting(CeQueueDto::getUuid) | |||
.containsOnly("p3"); | |||
assertThat(underTest.selectPendingByMinimumExecutionCount(db.getSession(), 3)) | |||
.isEmpty(); | |||
assertThat(underTest.selectPendingByMinimumExecutionCount(db.getSession(), 3 + Math.abs(new Random().nextInt(20)))) | |||
.isEmpty(); | |||
} | |||
@Test | |||
public void selectPendingByMinimumExecutionCount_does_not_return_non_pending_tasks() { | |||
} | |||
@Test | |||
public void test_delete() { | |||
insert(TASK_UUID_1, COMPONENT_UUID_1, PENDING); |