public ITask getTask(String taskId) { String name = "getTask"; int waittime = 2; while (true) { synchronized (service) { try { HIT hit = service.getHIT(taskId); // LOGGER.info(String.format("Retrieved HIT %s", hit.getHITId())); return new MturkTask(hit); } catch (InternalServiceException ise) { if (overTime(name, waittime)) { LOGGER.error(String.format("%s ran over time", name)); return null; } LOGGER.warn(format("{0} {1}", name, ise)); chill(waittime); waittime *= 2; } catch (ObjectDoesNotExistException odnee) { LOGGER.warn(format("{0} {1}", name, odnee)); } } } }
@Override public boolean makeTaskUnavailable( ITask task) { String name = "expireHIT"; while (true){ synchronized (service) { try{ service.forceExpireHIT(task.getTaskId()); return true; }catch(InternalServiceException ise){ LOGGER.warn(MessageFormat.format("{0} {1}", name, ise)); chill(1); }catch(ObjectDoesNotExistException odne) { LOGGER.warn(MessageFormat.format("{0} {1}", name, odne)); return false; } } } }
int numAvailableAssignments(ITask task) { String name = "availableAssignments"; while (true){ synchronized (service) { try{ HIT hit = service.getHIT(task.getTaskId()); return hit.getNumberOfAssignmentsAvailable(); }catch(InternalServiceException ise){ LOGGER.warn(MessageFormat.format("{0} {1}", name, ise)); chill(1); }catch(ObjectDoesNotExistException odne) { LOGGER.warn(MessageFormat.format("{0} {1}", name, odne)); return 0; } } } }
private boolean approveAssignment(String assignmentId) { Class clz = new Object(){}.getClass(); int waittime = 1; while (true) { synchronized (service) { try { service.approveAssignment(assignmentId, "Thank you."); return true; } catch (InternalServiceException ise) { if (waittime > maxWaitTimeInSeconds) { String msg = String.format("WARNING: Exceeded max wait time in %s.%s..." , clz.getEnclosingClass().getName() , clz.getEnclosingMethod().getName()); LOGGER.warn(msg); System.err.println(msg); } chill(waittime); waittime *= 2; } catch(ObjectDoesNotExistException odne) { LOGGER.warn(MessageFormat.format("{0} {1}", clz, odne)); return false; } } } }
ITask addAssignments(ITask task, int n) { Class name = new Object(){}.getClass(); int waittime = 1; while (true){ synchronized (service) { try { String id = task.getTaskId(); service.extendHIT(id, n, minExpirationIncrementInSeconds); return task; } catch(InternalServiceException ise){ LOGGER.warn(MessageFormat.format("{0} {1}; error codes: {2}", name, ise, StringUtils.join(ise.getErrorCodes(), ","))); if (waittime > maxWaitTimeInSeconds) { String msg = String.format("WARNING: Exceeded max wait time in %s.%s..." , name.getEnclosingClass().getName() , name.getEnclosingMethod().getName()); LOGGER.warn(msg); System.err.println(msg); } chill(waittime); waittime *= 2; }catch(ObjectDoesNotExistException odne) { LOGGER.warn(MessageFormat.format("{0} {1}", name, odne)); return null; } } } }