@Test public void testRenew() throws IOException, SurveyException, NoSuchMethodException, IllegalAccessException, InvocationTargetException , ParseException, InstantiationException { try { SurveyTasksTuple stuff = sendSurvey(1); Survey survey = stuff.s; ITask hit = stuff.hits; AbstractResponseManager responseManager = new MturkResponseManager(new MturkLibrary()); responseManager.makeTaskUnavailable(hit); if (! ((MturkResponseManager) responseManager).renewIfExpired(hit.getTaskId(), survey)) throw new RuntimeException("Didn't renew."); responseManager.makeTaskAvailable(hit.getTaskId(), responseManager.getRecord(survey)); responseManager.makeTaskUnavailable(hit); }catch(AccessKeyException aws) { LOGGER.warn(aws); System.out.println(aws); return; } catch (SurveyException se){ if (outcome[1]) throw se; else return; } }
private static Thread makeRunner( final Record record) { return new Thread(){ @Override public void run() { Scanner scanner = new Scanner(System.in); try { Runner.run(record); } catch (InsufficientFundsException ife) { System.out.println("Insufficient funds in your Mechanical Turk account. Would you like to:\n" + "[1] Add more money to your account and retry\n" + "[2] Quit\n"); int i; do { System.out.println("Type number corresponding to preference: "); i = scanner.nextInt(); if (i==2) System.exit(1); } while(i!=1); } catch (AccessKeyException aws) { System.out.println(String.format("There is a problem with your access keys: %s; Exiting...", aws.getMessage())); System.exit(0); } catch (IllegalAccessException | InterruptedException | IOException | InstantiationException | ClassNotFoundException e) { e.printStackTrace(); } finally { scanner.close(); } } }; }
public static void run( final Record record) throws InterruptedException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException, AccessKeyException { try { Survey survey = record.survey; int numTimesCalled = 0; do { // Log every 5 times this thing is called: if (numTimesCalled % 5 == 0) { LOGGER.info(String.format("Runner Thread called %d times.", numTimesCalled)); numTimesCalled++; } if (!interrupt.getInterrupt()) { surveyPoster.postSurvey(responseManager, record); } } while (stillLive(survey)); Object foo = new Object(){}; interrupt.setInterrupt(true, String.format("Target goal met in %s.%s" , foo.getClass().getEnclosingClass().getName() , foo.getClass().getEnclosingMethod().getName())); } catch (SurveyException e) { String msg = "Fatal error: " + e.getMessage() + "\nExiting..."; System.err.println(msg); LOGGER.fatal(e); interrupt.setInterrupt(true,"Error detected in edu.umass.cs.runner.Runner.run",e.getStackTrace()[1]); } finally { synchronized(interrupt) { surveyPoster.stopSurvey(responseManager, record, interrupt); } } }