Single custom code for multiple operations

+1 vote
Hi, We wanted to confirm if its okay to user a single custom code jar to accomplish multiple operations like add, fetch, update, delete. We have about 30-35 different operations to be performed for our app and below is what we are doing: We have a single custom code jar deployed which takes a request JSON that will have a key with name "requestCode", this will identify the operation to be performed. For eg, requestCode = 1 to get the data, requestCode = 2 to add the data, and so on. Then we have a switch statement on the requestCode which calls the appropriate method depending on the requestCode. Is this approach okay considering the concurrency of operations in production environment?
asked Feb 20, 2016 in Java by jitesh.h.lalwani (20 points)

1 Answer

+1 vote
Hi Jitesh,

It's recommended to have multiple custom code for operations like GET/POST/PUT/DELETE, but you can work with one as well. There is no issue with one custom code for all operations.

Regards,

Himanshu Sharma
answered Feb 21, 2016 by hs00105 (2,005 points)
Thank you for the reply.
Hi,

And what's your advice if I have to implement a custom code which will go to last long ??

Would it be better to distribute the task in a pool of background jobs working simultaneously ??

Although it would have to finish the job as quickly as possible in response to certain users actions, let say as close as possible to realtime.

Thank you very much.
Hi Catwalk,

It depends on the app use case that how you want to proceed. Let say there is a screen inside App which requires information from custom code response then you can't run the background job. It would be great if you can share an example of your use case. It will help me to suggest the best solution from my side.

Also, please elaborate this more (And what's your advice if I have to implement a custom code which will go to last long ??)

regards,
Himanshu Sharma
Hi Himanshu.

Sorry about muy question.

I'll try to explain myself better.

Every time a user makes an action inside the app, this action is registered in a collection.

Then I need to fan out this action for every user's feed who follow him.

Here it's explained in detail :
http://www.waistcode.net/blog/mongodb-newsfeed-schema-design-for-entexis

And here is where I have some doubts.

I don't know if it's better to distribute the task ( fan out ) in a pool of background jobs working simultaneously or to have only one job working alone.

Let me know if you need more details.

Thank you very much in advance.
Hi,

Apologies to miss out your question. If I understood your use case correctly then you may require an option to trigger background job on the certain action performed by the user. If yes, then let me know. It will help me to provide better support to you.

Regards,
Himanshu Sharma
Hi Himanshu.

Yes, it could be a solution.

How could I get to trigger a background job on a certain action ???

Thank you in advance.
Hi,

It can be achievable easily on the success of your action performed by user, you can trigger custom code which basically have the code. You can trigger that code as an Async call, so that it will run on the background and you don't have to wait for that.

Let me know if it helps.

regards,
Himanshu Sharma
Hi Himanshu,

But how could I trigger an async call using java ??

Because I'm implementing this logic on the server.

However maybe it could be more efficient if I schedule this job, I am not sure.

By doing this way, it could process several actions on every call.

It is assumed that every user could generate many actions continuosly.

Thank you Himanshu.
In that case, you can schedule your custom code from dashboard and based on user activity take certain actions.

regards,
Himanshu Sharma
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...