amazon web services - AWS Simple workflow notification technique -


i'm new aws swf , task give notification(thru email) when activity fails during first attempt only. i'm using settable<boolean> flag value not reliable because workflow running async. here's code:

 final asyncexecutor asyncexecutor = new asyncretryingexecutor(retrypolicy, workflowclock);  final settable<boolean> notifyexception = new settable<>();      new trycatch() {         @override         protected void dotry() throws throwable {             asyncexecutor.execute(() -> new trycatch() {                 @override                 protected void dotry() throws throwable {                     promise<activityone> activityone = activityoneclient.performaction(activityonerequest);                 }                  @override                 protected void docatch(throwable e) throws throwable {                     if (!notifyexception.isready()) {                         // perform notification service here!!                         notifyexception.set(true);                     } else {                         // nothing. notification sent first time :)                     }                      throw e;                 }             });         }          @override         protected void docatch(throwable e) throws throwable {             system.out.println("======");             system.out.println("catch all!! " + e.getmessage());             system.out.println("======");         }     }; 

the notifyexception 's value changing though explicitly set value true inside if statement. result of code perform more 1 notification service.

====update===

 final asyncexecutor asyncexecutor = new asyncretryingexecutor(retrypolicy, workflowclock);  final settable<boolean> notifyexception = new settable<>();      new trycatch() {         @override         protected void dotry() throws throwable {             asyncexecutor.execute(() -> new trycatch() {                 @override                 protected void dotry() throws throwable {                     promise<activityone> activityone = activityoneclient.performaction(activityonerequest);                 }                  @override                 protected void docatch(throwable e) throws throwable {                     if (!notifyexception.isready()) {                         activityoneclient.notify();                         notifyexception.set(true);                     }                     throw e;                 }             });         }          @override         protected void docatch(throwable e) throws throwable {             system.out.println("======");             system.out.println("catch all!! " + e.getmessage());             system.out.println("======");         }     }; 

when re-throw exception, activityoneclient.notify() executed on last retry of asyncexecutor, if dont re-throw, activityoneclient.notify() executed automatically. need notify if exception occur first time.

the code looks okay-ish (haven't run it).

your problem somewhere else. way flow framework works every time there work workflow workers or activity workers pick task, run , report results. reporting results means result of execution captured in workflow history.

whenever history changes decider (workflow) worker runs , makes decision should happen next. under covers decider replays history , makes decisions beginning of time. now, decisions match what's in history decider goes on until hits new.

simple example. have workflow has 3 steps:

  • activity1
  • activity2 - depends on result of activity1
  • activity3 - depends on result of activity2

[ keep in mind multiply activities can run @ same time, , if there isn't link between output of activity , input other flow framework move ahead , schedule multiple things in parallel. keeping simple idea ]

at t0 when workflow starts there no history, decider runs , activity1 scheduled.

at t1 activity1 workers pick task, execute , report result.

at t2 result of activity1 updating history decider scheduled , runs + reads history. sees activity1 should run, sees in history, sees completed, schedules activity2

at t3 activity2 workers pick task, execute , report result.

at t4 result of activity2 updating history decider scheduled , runs + reads history. sees activity1 should run, sees in history, sees completed. sees activity2 should run, sees in history, sees it's completed , move on activity3. schedules activity3.

and on.

your problem code in decider dictates flow run every time decider runs (every decision). when decider reaches activity see has run , has thrown , exception , go though code sets flag + sends email.

when exponential retries kick is, flag set, code sends email run on every decision (the decider stateless , state built based on history).

what in particular case move part sends email in own activity. way decider see in history , fast forward instead of running each time.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -