Hello community.
I have a Codeless method WriteHPdata that saves input object (method argument data) in specified table (method argument table_name) and set 1:1 relation between this new record and record in table HP_list that contains serial property = method argument hp_sn.
In HP_list table we have a list of devices that new records belongs to.
There is next issue: sometimes when we call method WriteHPdata new record is saved in specified table, but above mentioned relation is not set. Thus, in most cases method is executed completely, but sometimes only new record save (without relation set) is done.
Part of method that executes new records saving and relation set is below:
As we can see, I even add while operator and new record relation existence checking. I use Load Object Relations block to get a list of new record relations. Then convert it into the text. If the length of this text < 10, it means there are no relations. So, we should set it. But
In table we can see next situation:
Method WriteHPdata we call with same parameters (table_name, data, hp_sn). But in some cases (5/13) relation is not set. What is a reason of this?
One more moment. Sometimes in RT logs window I see next message: | SERVER_CODE | ERROR | [3505952] Error: The API request has been rejected because it requires scaling for processing. Switch to the Cloud9 or Cloud99 plan to enable the Super Scaling option. at checkStatus (/usr/local/lib/node_modules/backendless-coderunner/node_modules/backendless-request/lib/request.js:330:9) at processTicksAndRejections (internal/process/task_queues.js:95:5)
Can it be a reason of “partly” executed method WriteHPdata issue?
Hi @Oles_Lototsiy
The Springboard plan has a number of limitations. Requests that exceed this limit will return the error.
To make sure that you save data in an atomic way you need to rework the logic and use transactions. Transaction API
Regards,
Viktor
If I understand correctly, calling of WriteHPdata method we should consider as calling of Save object in Backendless and Set Object Relations methods (separately) that is limited due to Springboard plan (because they work with API services). I suppose there are some limits in number of calling these methods (for instance per minute). In other plans these limits are less. Am I right?
Hi @Oles_Lototsiy
If I understand correctly, calling of WriteHPdata method we should consider as calling of Save object in Backendless and Set Object Relations methods (separately)
To ensure that both records are created or not created during one request you should use Transactions API which I mentioned above. In the transaction, you will guarantee that changes are applied as one atomic operation or not applied at all.
I suppose there are some limits in number of calling these methods (for instance per minute). In other plans, these limits are less. Am I right?
Other plans do not have such limits since they are designed for production. But in your case, the main problem you have is that your interaction with DB is lacking atomicity. The Springboard plan limits just helped to detect this.
Just try to use transactions API and you will never encounter partial creation of data again.
Regards,
Viktor
I changed logic according to instruction. Now it looks like this:
It works correctly - method is executed “completely” all the time (at least for now). Thank you for your help.
But I have noticed other thing. When I call method WriteHPdata for instance 8-10 times (during 2-3 sec time interval) only 4-5 records are saved in table. So, method is executed 4-5 times instead of 8-10. And in RT logs window I see next message:
| SERVER_CODE | ERROR | [869737] Error: The API request has been rejected because it requires scaling for processing. Switch to the Cloud9 or Cloud99 plan to enable the Super Scaling option. at checkStatus (/usr/local/lib/node_modules/backendless-coderunner/node_modules/backendless-request/lib/request.js:330:9) at processTicksAndRejections (internal/process/task_queues.js:95:5)
I suppose Springboard plan is a reason of that “new issue”. Am I right?
@Oles_Lototsiy
Yes, you are right, there are limits on the number of requests in Springboard. In Cloud9 and Cloud99 pricing plans, you won’t have these limitations.
Regards,
Viktor