amazon web services - How to periodically schedule a same activity when the previous one is still excuting -
my goal have workflow periodically (every 30 seconds) add same activity (doing nothing sleep 1 minute) tasklist. have multiple machines hosting activity workers poll tasklist simultaneously. when activity got scheduled, 1 of workers can poll , execute.
i tried use cron decorator create dynamicactivityclient , use dynamicactivityclient.scheduleactivity() schedule activity periodically. however, seems the activity not scheduled until last activity finished. in case, activity got scheduled every 1 minute rather 30 seconds set in cron pattern.
the package structure same aws sdk sample code: cron there other structure recommended achieve this? new swf.any suggestion highly appreciated.
the cron decorator internally relies on asyncscheduledexecutor design written wait asynchronous code in invoked method complete before calling cron again. behavior witnessing expected. workaround not invoke activity code under cron, code in different scope. like:
// field settable<void> invokenextactivity = new settable<>(); void executecron() { scheduledexecutor.execute(new asyncrunnable() { @override public void run() throws throwable { // instead of executing activity here unblock // execution in different scope. invokenextactivity.set(null); } }); // recursive loop each activity invocation // gated on invokenextactivity executeactivityloop(invokenextactivity); } @asynchronous void executeactivityloop(promise waitfor) { activityclient.executemyactivityonce(); ivnokenextactivity = new settable<>(); executeactivityloop(ivnokenextactivity); }
i recommend reading trycatchfinally documentation understanding of error handling , scopes.
another option rewrite asyncscheduledexecutor invoke invoked.set(lastinvocationtime) not dofinally after calling command.run()
Comments
Post a Comment