Backendless Support
 
Waiting for user's response

custom logic not working

Hi. I am working on custom backend logic. Actually i have to insert rows in a table when a user register to the application. But to keep it simple initially I just change the name of user after registration. I have deployed the custom logic but it didn't working.

First I didn't use Async then I received this email

-------------------------------------

This is a notification to inform you that a business logic code running in your application has been interrupted prematurely. The interruption was caused by the business logic taking longer than the plan limit.

The information about the limit can be found below.

Application name: StuNexus

Application ID: CF512434-CCA8-067C-FF92-D76481A44000

Version name: v1

Maximum allowed business logic runtime: 5 seconds

If you are already aware of this condition and are working on a solution, please ignore this email. Otherwise, it is important to make any adjustments to the business logic so it completes the execution within the allotted time or increase the limit by purchasing a function pack.

---------------------------------------------------

and if I use Async then it did not change the value.

here is my code for logic

Kindly help

  1. package com.stunexus.events.user_service;

    import com.backendless.servercode.ExecutionResult;

    import com.backendless.servercode.RunnerContext;

    import com.backendless.servercode.annotation.Async;

    import java.util.HashMap;

    public class GenericUserEventHandler extends com.backendless.servercode.extension.UserExtender

    {

    @Async

    @Override

    public void afterRegister( RunnerContext context, HashMap userProperties, ExecutionResult<HashMap> result ) throws Exception {

    userProperties.put("name", "David Joey");

    result.getResult().put("name", "David Joey");

    }

    }

Leave a Comment

Comments (21)

photo
1

Hi Mubtada,

Currently I can see only beforeRegister handler deployed in your application. Could you please also deploy the one you mention so that we could try to test it?

photo
1

The problem is the deployed handler is not working. According to this line "userProperties.put("name", "David Joey");" It should have change the name of user to "David Joey" but it is not working.

photo
1

But the code you provided is for afterRegister event, and the event handler you have deployed is beforeRegister. If the deployed one (beforeRegister) is not working, please provide its source code, too.

photo
1

I have deployed the afterRegister handler. plus I'm having the same problem 'Alaxender' has. I have also mentioned the email content in the problem description.

My application ID is: CF512434-CCA8-067C-FF92-D76481A44000

photo
1

You can see that I have only afterRegistration handler

photo
1

Yes, I can see it now.

I just tried the following curl request several times and it worked fine, could you please verify it too?

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}

span.s1 {font-variant-ligatures: no-common-ligatures}

  1. curl -H application-id:CF512434-CCA8-067C-FF92-D76481A44000 -H secret-key:6B6FDEEC-0909-2FF2-FF89-7A51CEAD9E00 -H Content-Type:application/json -d '{"email":"test@backendless.com", "password":"qwe", "name":"TestBackendless"}' -X POST https://api.backendless.com/v1/users/register

photo
1

It's not working. I have deployed the above mentioned code but it did not change the user's name to 'David Joey'. I have attached a screenshot of my User Table plus i have mentioned the rows on which i have tested the logic,

Files: test.JPG
photo
1

The afterRegister operation only modifies the resulting response when the user is already registered, so in your data table you'll have the initial name. Also, in your case, since user confirmation is required, you will not even see the result of afterRegister actions.

In order to modify the user's name before the actual saving into the data service, you'll need to use beforeRegister handler.

photo
1

Its not working. Now I have 3 handler, 1 for beforeRegistration, 1 for afterRegistration and 1 custom business logic to insert rows into tables. I have deployed these handler but it is not working. Here is my code for handlers

  1. package com.stunexus.events.custom_events;

    import com.backendless.Backendless;

    import com.backendless.servercode.RunnerContext;

    import com.backendless.servercode.annotation.Asset;

    import com.backendless.servercode.annotation.Async;

    import com.backendless.servercode.annotation.BackendlessEvent;

    import com.backendless.servercode.annotation.BackendlessGrantAccess;

    import com.backendless.servercode.annotation.BackendlessRejectAccess;

    import java.util.Collections;

    import java.util.HashMap;

    import java.util.Map;

    /**

    * UserskillEventHandler handles custom event "userskill". This is accomplished with the

    * BackendlessEvent( "userskill" ) annotation. The event can be raised by either

    * the client-side or the server-side code (in other event handlers or timers).

    * The name of the class is not significant, it can be changed, since the event

    * handler is associated with the event only through the annotation.

    */

    @BackendlessEvent( "userskill" )

    public class UserskillEventHandler extends com.backendless.servercode.extension.CustomEventHandler

    {

    @Async

    @Override

    public Map handleEvent( RunnerContext context, Map eventArgs )

    {

    HashMap contact = new HashMap();

    contact.put( "name", "test" );

    Map savedContact = Backendless.Persistence.of( "Organization" ).save( contact );

    return Collections.emptyMap();

    }

    }

  2. package com.stunexus.events.user_service;

    import com.backendless.Backendless;

    import com.backendless.BackendlessCollection;

    import com.backendless.commons.util.SocialType;

    import com.backendless.persistence.BackendlessDataQuery;

    import com.backendless.property.UserProperty;

    import com.backendless.servercode.ExecutionResult;

    import com.backendless.servercode.RunnerContext;

    import com.backendless.servercode.annotation.Async;

    import java.util.HashMap;

    import java.util.Map;

    public class GenericUserEventHandler extends com.backendless.servercode.extension.UserExtender

    {

    @Async

    @Override

    public void beforeRegister( RunnerContext context, HashMap userProperties ) throws Exception

    {

    userProperties.put("name","David Joey");

    }

    @Async

    @Override

    public void afterRegister( RunnerContext context, HashMap userProperties, ExecutionResult<HashMap> result ) throws Exception

    {

    Backendless.Events.dispatch( "userskill", null );

    // add your code here

    }

    }

Kindly help

here it is another thing that I have deployed these handlers without debugging, is that a problem?

photo
1

??????

photo
1

Run your code in CodeRunner Debugger and make sure it works there first before uploading the code to Backendless.

photo
1

I don't know how to pass input for verification in CodeRunner Debugger. can you please tell me how to do that? I'm working on android.

photo
1

Business Logic is written either in Java or JavaScript. Android has nothing to do with it.

I do not understand what "pass input for verification" is. Please follow the user guide which describes the process precisely:

Java:

https://backendless.com/documentation/business-logic/java/apieng_service_debugging.htm

JS:

https://backendless.com/documentation/business-logic/js/apieng_service_debugging.htm

photo
1

I mean that when the Debugger is 'waiting for events...' what should I do next? how to gave input there?

photo
1

If you implemented an event handler, then you need to issue an API call which will be trigger your code. Suppose you created "beforeRegister" event handler. That code will be triggered when you call the "register" API.

photo
1

I have registered a user while the Debugger was waiting for events, but event handler code is not working. Kindly Help

photo
1

When you run CodeRunner locally, what does the output of the program look like? (from start to finish)

photo
1

I have attached the screenshot.

photo
1

What API do you use to trigger the code?

photo
photo
1

I have the same issue today. Approximately every second query to my custom handlers returns me "Custom business logic execution has been terminated because it did not complete in permitted time - 5 seconds". Previously all works fine.

photo
1

Hi Alexandr,

Please create a dedicated topic and provide your app ID and an example of the call so that we could test it. Thanks in advance and sorry for the inconvenience!

photo