Hello everyone!
Since I can’t use any kind of context in the timer execution body, I decided to make an HTTP request to another service from a timer.
My timer looks like follows:
import 'bla-bla-lba' from 'path'
Backendless.ServerCode.addTimer({
name: 'Timer_name',
frequency: {
schedule: 'daily',
repeat: { every: 1 },
},
async execute() {
await Backendless.UserService.loginAsGuest();
const userId = Backendless.UserService.currentUser.objectId;
await Backendless.UserService.assignRole(userId, UserRole.Scheduler);
try {
await Backendless.APIServices.invoke('myService', 'refreshAction');
} catch (error) {
console.log(error);
}
await Backendless.UserService.logout();
await Backendless.Data.of(User).remove(userId);
},
});
The issue reproduces when the timer starts invoking the API service. The server becomes irresponsible at all until the debugger is deattached.
Please notice, the issue doesn’t reproduce when the timer is deployed, the server stucks when I’m in the debug mode only.
Additional info may be helpful:
java.util.concurrent.CompletionException: java.lang.NullPointerException: Cannot invoke "java.util.concurrent.CompletionStage.whenComplete(java.util.function.BiConsumer)" because the return value of "com.backendless.servercode.services.invoker.HostedInvoker.invoke(com.backendless.coderunner.commons.protocol.RequestServiceInvocation, com.backendless.servercode.ExecutionType, boolean)" is null
UPD:
As of now, we rewrote the code to use then
chain syntax, but I’m afraid if the Java thread you allocate for the timer doesn’t complete the inner async logic (that doesn’t resolve by our code) before destroy itself. When we had added Promise.resolve(result)
for the final promise returned by the chain, the server stucked again. So, the code in the timer is not awaiting now.
Thank you!