Backendless Support
 
Answered

Server code Timer transaction

I am currently facing some database performance issues in my custom server code timer. I need to do:

1) query my table for new records

2) send a push notification for each new record

3) update record with a flag that the push notification has been sent

When the Backendless servers are a bit too busy, I run out of execution time (free version, 5 seconds) because my database actions take too long, It then happens that a push notification is sent out but the record has not been updated. Is there any kind of mechanism I can use to encapsulate three above steps into one logical transaction?

Leave a Comment

Comments (8)

photo
1

Hi,

You could separate the record update to afterPublish event handler, this will also decrease the number of database transaction in your timer.

photo
1

Hi thanks for your suggestion. Would moving part of my implementation to an afterPublish handler extend my overall execution time?

If so, how would I pass some sort of ID from my Timer to the afterPublish handler? Also, what are the contents of its Object message parameter?

photo
1

If you separate a part of the implementation, you'll have 5 seconds for a timer and another 5 seconds for a handler, thus you'll have the time available doubled.

I suppose you'll need to put that ID into message itself (odds are you already put there some kind of ID). Object message is the same object you put to the send() method when sending a notification.

photo
1

Or you can use Backendless.Cache.

photo
photo
1

I have added a MessagingExtender implementation but it is not called when I send a push notification from the Timer code. Is adding the following class to my project enough to register it or do I need to do something more?

@Asset( "*" )

public class GroningenChannelEventHandler extends MessagingExtender

{

private void log(String line) { ... }

@Override

public void beforePublish(RunnerContext context, Object message, PublishOptions publishOptions, DeliveryOptions deliveryOptions ) throws Exception

{

// add your custom logic here

}

@Override

public void afterPublish(RunnerContext context, Object message, PublishOptions publishOptions, DeliveryOptions deliveryOptions, ExecutionResult<MessageStatus> result ) throws Exception

{

log("GroningenChannelEventHandler afterPublish");

}

}

photo
1

Can you see these new handlers on "Production" tab on Business Logic console tab?

photo
1

No, I don't see the new handlers there. I just added the class to my project. Is that correct or do I need to do another step in the project or in the online backendless console?

photo
1

Hi,

You can find how to deploy server code here:

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

Regards, Vlad

photo