}
public Optional<CeQueueDto> peek(DbSession session) {
- List<String> taskUuids = mapper(session).selectEligibleForPeek(ONE_ROW_LIMIT);
- if (taskUuids.isEmpty()) {
+ List<EligibleTaskDto> eligibles = mapper(session).selectEligibleForPeek(ONE_ROW_LIMIT);
+ if (eligibles.isEmpty()) {
return Optional.absent();
}
- String taskUuid = taskUuids.get(0);
- return tryToPeek(session, taskUuid);
+ EligibleTaskDto eligible = eligibles.get(0);
+ return tryToPeek(session, eligible);
}
- private Optional<CeQueueDto> tryToPeek(DbSession session, String taskUuid) {
- int touchedRows = mapper(session).updateIf(taskUuid,
+ private Optional<CeQueueDto> tryToPeek(DbSession session, EligibleTaskDto eligible) {
+ int touchedRows = mapper(session).updateIf(eligible.getUuid(),
new UpdateIf.NewProperties(IN_PROGRESS, system2.now(), system2.now()),
new UpdateIf.OldProperties(PENDING));
if (touchedRows != 1) {
return Optional.absent();
}
- CeQueueDto result = mapper(session).selectByUuid(taskUuid);
+ CeQueueDto result = mapper(session).selectByUuid(eligible.getUuid());
session.commit();
return Optional.of(result);
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.ce;
+
+public class EligibleTaskDto {
+ private String uuid;
+ private int executionCount;
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public EligibleTaskDto setUuid(String uuid) {
+ this.uuid = uuid;
+ return this;
+ }
+
+ public int getExecutionCount() {
+ return executionCount;
+ }
+
+ public EligibleTaskDto setExecutionCount(int executionCount) {
+ this.executionCount = executionCount;
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return "EligibleTaskDto{" +
+ "uuid='" + uuid + '\'' +
+ ", executionCount=" + executionCount +
+ '}';
+ }
+}