Home How to continue async task after rest response in grails3
Reply: 0

How to continue async task after rest response in grails3

user3611
1#
user3611 Published in June 19, 2018, 2:42 pm

I have a Rest API, where I have called an aws service and save the records on a single endpoint at the same time. In order to respond quickly, I want to run the aws service asynchronously, even after the API responds too in grails. Please suggest how could I achieve it?

I have used async task. As

def Method1(){
   task{
     //long running task
     Thread.sleep(50000)
    }
   saveRecords()
   def message=["msg":"success"]
   return message
}

After the task completion, I have got the exception like:-

java.lang.NullPointerException
at org.apache.catalina.connector.Request.notifyAttributeAssigned(Request.java:1513)
at org.apache.catalina.connector.Request.setAttribute(Request.java:1503)
at org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.java:539)
at org.grails.web.util.WebUtils.storeGrailsWebRequest(WebUtils.java:448)
at org.grails.plugins.web.async.WebRequestPromiseDecorator$_decorate_closure1.doCall(WebRequestPromiseDecorator.groovy:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1432)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021)
at groovy.lang.Closure.call(Closure.java:426)
at org.codehaus.groovy.runtime.ConvertedClosure.invokeCustom(ConvertedClosure.java:54)
at org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:124)
at com.sun.proxy.$Proxy98.get(Unknown Source)
at reactor.rx.Promises$1.accept(Promises.java:122)
at reactor.rx.Promises$1.accept(Promises.java:119)
at reactor.core.reactivestreams.PublisherFactory$ForEachBiConsumer.accept(PublisherFactory.java:411)
at reactor.core.reactivestreams.PublisherFactory$ForEachBiConsumer.accept(PublisherFactory.java:375)
at reactor.core.reactivestreams.PublisherFactory$SubscriberProxy.request(PublisherFactory.java:318)
at reactor.rx.Promise.onSubscribe(Promise.java:589)
at reactor.rx.Stream$SubscribeOn.accept(Stream.java:3128)
at reactor.rx.Stream$SubscribeOn.onSubscribe(Stream.java:3134)
at reactor.core.reactivestreams.PublisherFactory$ReactorPublisher.subscribe(PublisherFactory.java:259)
at reactor.rx.Streams$1.subscribe(Streams.java:183)
at reactor.rx.Stream$82.subscribe(Stream.java:2925)
at reactor.rx.Stream$StreamDispatchedSubscribe.accept(Stream.java:3167)
at reactor.rx.Stream$StreamDispatchedSubscribe.accept(Stream.java:3156)
at reactor.core.dispatch.AbstractLifecycleDispatcher.route(AbstractLifecycleDispatcher.java:160)
at reactor.core.dispatch.SingleThreadDispatcher$SingleThreadTask.run(SingleThreadDispatcher.java:79)
at reactor.core.dispatch.RingBufferDispatcher$3.onEvent(RingBufferDispatcher.java:156)
at reactor.core.dispatch.RingBufferDispatcher$3.onEvent(RingBufferDispatcher.java:153)
at reactor.jarjar.com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:128)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.328187 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO