Alternative to async API calls in CodeRunner?

Hi, since async API calls are no longer be made in CodeRunner, what would be the alternative for this? The compatibility notice of Oct 29th says to replace all the async calls with synchronous ones. However, this makes my app’s custom business logic work a lot slower, which seem really impractical. Is there any alternative to this?

Thanks,
Katia

Hi Katia

Unfortunately at this point I can’t suggest you an alternative. In further releases an option to add additional streams for BL will be available in Marketplace. At the moment you may make your handlers asynchronous via your developers console.http://support.backendless.com/public/attachments/b2309226207d21114cfef336d018ea8c.png</img>

Regards Anton

Hi Anton,

Unfortunately this doesn’t work. If I check this Async box the handler never gets executed, and the row I’m inserting gets inserted twice. It’s a handle called on create.

Any advice how to fix this?

Thanks!

So what’s the point of having server code if it can’t run in background thread?!

I have “afterCreate” handler that does some insertions and computations for me. I’d like to be able to run it async and not block my UI. I checked the box to Async but then it doesn’t call my event handler. I was about to release the app on the app market but now have to wait to resolve this problem.

It was working fine until yesterday. Hope that issue is going to be resolved soon.

Hello!

Katia, please clarify what is “The compatibility notice of Oct 29th”. New threads creation inside business logic code is forbidden for a plenty of time. Hence, async calls from BL are also forbidden.
Sami, you can invoke any handler async. It really doesn’t matter how the action has been invoked - sync or async. The only forbidden action is new threads creation inside the BL code. Clarify please what is “it doesn’t call my event handler”? What is “it” here?

I was testing the code and nothing was invoking the handlers (create, update, delete). I tried everything and then I unchecked the Async check box. Everything worked fine but the problem was blocking my UI of course. So I began testing. Removed the @Async annotation from the Java BL code. Handlers were working fine but continued to block the UI, added the @Async, no handler was invoked.

Hope that was clear enough!

Hi Alexandr,

I have some event handlers that are invoke when create, update, removed is initiated from my app.
Look at the attached file. Everything worked fine up until one day everything stopped.
I was testing the code and nothing was invoking the handlers (create, update, delete). I tried everything and then I unchecked the Async check box. Everything worked fine but the problem was blocking my UI of course. So I began testing. Removed the @Async annotation from the Java BL code. Handlers were working fine but continued to block the UI, added the @Async, no handler was invoked.

Hope that was clear enough!

Would you also clarify what does that notice mean?

http://support.backendless.com/knowledge-base/article/compatibility-notice-using-async-api-calls-in-coderunner_1

I’ve attached the notice I’m referring to.
However, much more importantly, as Sami explains, event handlers don’t get executed when the corresponding event happens, if the Async box has been checked. How do we asynchronously invoke an event handler, let’s say one that should be invoked after inserting a row in a table?

Ok, thank you for responses. It looks like that there is a regression on our side, we shall investigate it.

About the article: it’s pretty old, it has been posted in 2014. As you see the date “Wednesday, October 29th” is valid only for 2014. Before that Wednesday on 29th Oct has been in 2008.
So, you shouldn’t change your code.

Unfortunately, I cannot reproduce your issues.
Here is how my handlers look like: https://monosnap.com/file/8G7GTVJHwUPCRTXf3yGTIvLhI6dJGF
Each handler saves an object to table “EventLog”, so handlers code looks like this:

@Async
@Override
public void afterCreate( RunnerContext context, Test test, ExecutionResult<Test> entity ) throws Exception
{
new EventLog().setName( "afterCreate" ).save();
}

Then I create, update and remove object in “Test” table through REST-console.
It works fine for me, I get new objects created in “EventLog” table with expected names. I’ve also tried to reproduce it with “before” handlers, but also without success.
If it’s possible, let me know:

  • what client is used for API calls ( REST, Android… )
  • what language is used for servercode
  • what exactly goes wrong when you turn on “async” mode: requests fail, or requests passes but handlers are not being invoked

Perhaps it worth to mention that I’m using backandless pro through AWS. I’m using the swift SDK and Java for server code.

Nothing goes wrong when I turn on Async. Just nothing gets executed. I have it on local debugging mode and there is nothing printed on the console. As soon as I change it to Sync everything works fine and I get logs printed out on the console.

So, request passes, but handlers are not invoked? Is it correct?
Also tell please, what is the “pro” version you’re using?

That’s correct!

This is what I’m using (pro version)
https://aws.amazon.com/marketplace/pp/B01MDLLYYY

Just wanted to confirm that it’s still not working. I downloaded a new CodeRunner and then new generated code from Backendless. I didn’t put any code in the BL code…just some logs. Unfortunately, the result was the same. Sync works, Async doesn’t. Check out my CodeRunner runner.properties file. Could that be the issue. Just want to remind you that it always worked until two days ago. I have not changed anything on the code.

@Async
@Override
public void afterCreate( RunnerContext context, RLMUnmanaged_Wish rlmunmanaged_wish, ExecutionResult<RLMUnmanaged_Wish> result ) throws Exception
{
  // add your code here
  System.out.println("afterCreate just callled");
}

system.server.url =  http://ec2-54-173-217-189.compute-1.amazonaws.com:80/api



system.redis.master.host = ec2-54-173-217-189.compute-1.amazonaws.com
system.redis.master.port = 7738



genericservice.loadall_from_libs = false
system.services.exclude.jar = backendless.jar,servlet-api-*.jar,weborb-*.jar
system.thread.manipulation.exclude.classes = weborb.cloud.AmazonBillingClient
system.weborb.path = ./none.jar



system.pool.core = 20
system.type = LOCAL
system.repo.path = ../repo/



# in seconds
allowedHosts.refreshTime = 240



enterprise.allowedHosts = localhost,\
  127.0.0.1,\
  api.backendless.com,\
  backendless.chargify.com,\
  backendlesstest.chargify.com,\
  ec2-54-173-217-189.compute-1.amazonaws.com

Thank you for these details.

What about async handlers in cloud? Do you face the same issue, or they work correctly?

Not sure if I understand the question but if you are asking me wether Async works when I deploy, then no.

None of the handlers get called on Async if there is create, update, delete. That’s the bottom line. Perhaps I can give you access to the console and you test it yourself?
My team is getting furstrated and desperate. It’s a very serious issue for us.

Yes, it would be really helpful because we cannot reproduce it on local environment.

Please contact us at support@backendless.com
Add a link to this topic into the letter.

Thanks Alexandr! Just sent an email with all the info you’d need.

Hope to get it resolved soon!

Thank you for sharing! I’ve tested your app and this issue has been reproduced. I guess that somehow taskman has been stopped and it caused the issue. Try to restart it.