use of net.petafuel.styx.keepalive.entities.WorkerType in project styx by petafuel.
the class TaskRecoveryDB method getQueuedTasks.
/**
* Returns all persisted tasks that were previously marked as queued/waiting for execution and were not yet executed
* by a Worker Thread within the previous application runtime
*
* @return Returns a map of K: Task Object | V: Assigned Worker Type
*/
public static Map<WorkableTask, WorkerType> getQueuedTasks() {
Connection connection = Persistence.getInstance().getConnection();
Map<WorkableTask, WorkerType> queuedTasks = new LinkedHashMap<>();
try (CallableStatement query = connection.prepareCall("{call get_queued_tasks()}")) {
try (ResultSet resultSet = query.executeQuery()) {
if (!resultSet.isBeforeFirst()) {
return queuedTasks;
}
queuedTasks = TaskRecoveryFactory.modelFromDatabase(resultSet);
}
} catch (SQLException e) {
LOG.error("Unable to load queued tasks: SQLState: {} Error: {}", e.getSQLState(), e.getMessage());
}
return queuedTasks;
}
use of net.petafuel.styx.keepalive.entities.WorkerType in project styx by petafuel.
the class TaskRecoveryFactory method modelFromDatabase.
static Map<WorkableTask, WorkerType> modelFromDatabase(ResultSet resultSet) throws SQLException {
LinkedHashMap<WorkableTask, WorkerType> tasks = new LinkedHashMap<>();
while (resultSet.next()) {
UUID id = UUID.fromString(resultSet.getString("id"));
String goal = resultSet.getString("goal");
String classname = resultSet.getString("class");
WorkerType type = WorkerType.valueOf(resultSet.getString("worker_type"));
WorkableTask recoveredTask;
try (Jsonb jsonb = JsonbBuilder.create()) {
recoveredTask = TaskRecoveryFactory.factory(classname, jsonb.fromJson(goal, JsonObject.class));
TaskRecoveryDB.setFinallyFailed(id, "Task was recovered and re-queued as new Task", TaskFinalFailureCode.RECOVERED_AND_QUEUED);
tasks.put(recoveredTask, type);
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
LOG.error("Unable to recover Task {}: {}", id, e.getMessage());
} catch (NoSuchMethodException unavailableConstructor) {
LOG.error("Unable to recover Task {}: Seems as if there is no empty public constructor available for reflection -> {}", id, unavailableConstructor.getMessage());
} catch (Exception unknown) {
TaskRecoveryDB.setFinallyFailed(id, "Unable to recover Task: " + unknown.getMessage(), TaskFinalFailureCode.UNABLE_TO_RECOVER);
LOG.error("Unable to recover Task {} due to an unexpected exception: {}", id, unknown.getMessage());
}
}
return tasks;
}
use of net.petafuel.styx.keepalive.entities.WorkerType in project styx by petafuel.
the class TaskRecoveryDB method getInterruptedTasks.
/**
* Returns all persisted tasks that were previously marked as running/executing and were unable to be resolved
* within the previous application runtime
*
* @return Returns a map of K: Task Object | V: Assigned Worker Type
*/
public static Map<WorkableTask, WorkerType> getInterruptedTasks() {
Connection connection = Persistence.getInstance().getConnection();
Map<WorkableTask, WorkerType> interruptedTasks = new LinkedHashMap<>();
try (CallableStatement query = connection.prepareCall("{call get_interrupted_tasks()}")) {
try (ResultSet resultSet = query.executeQuery()) {
if (!resultSet.isBeforeFirst()) {
return interruptedTasks;
}
interruptedTasks = TaskRecoveryFactory.modelFromDatabase(resultSet);
}
} catch (SQLException e) {
LOG.error("Unable to load interrupted tasks: SQLState: {} Error: {}", e.getSQLState(), e.getMessage());
}
return interruptedTasks;
}
Aggregations