How to automise frequently made calls to an API - spring

Im facing an issue and was wondering if there is some library/framework or something to help me out.
Basically i have method in an API that creates an object for me but the problem is that this is not returned to me right away but is created later in time.
all i get is a guid on method call and have to manually check in the future if my object is created and if it isnt try again.
So my wish is to somehow automise this maybe? My thoughts were for using jobs or mqueues.
Any suggestions are really appreciated. The languages im allowed to use is nestjs or spring boot.

It sounds like you're looking to set up a dynamic cron job after your API kicks off the event, and then have those cron jobs possibly create more cron jobs or send out notifications. Not sure what the Spring Boot alternative would be, but a CRON is definitely what it sounds like you need (at least to me)

Related

Is it right pattern of using Spring batch if one task that is launched through SCDF API call will launch other task through SCDF API calls?

I have a requirement to have a schedule batch that will identify what are the batches I need to restart or re-submit(as new job instance). Schedule batch will identify and call SCDF API to launch tasks. Is it really good design pattern to have a such batch ?
I can implement the above require pattern but is is good practice or anyone can suggest what is alternate way of doing it.
I see nothing wrong in implementing that requirement with Spring Batch (it would be a single step job with a simple tasklet). The question you should be asking is that do you really need a Spring Batch job for that? What would you gain from using Spring Batch? Most interesting features won't be used for that job (restartability, fault-tolerance, transaction management, etc), so the benefit/cost ratio is low IMO.
I have seen folks putting similar logic (db query + rest call) in a shell script scheduled with crontab. And I see nothing wrong with this approach neither.
So it really depends on how you want to implement that requirement.

Laravel 5.2 - Creating a Job API

So in my API there are a few places where it is running a process / report that is either hitting a timeout or simply just taking WAY too long. I'd like to defer these jobs off to a queue and instead return a key in my response. The front end would then ping a service using that key to determine the status of its particular job in the queue. This way we don't have hanging ajax calls for 2 - 3 minutes. Maybe I could even create a queue viewer that would allow you to review the jobs in it and even cancel some etc.
Does Laravel have something built in or is there a package for this already? Are there other better options for dealing with this kind of issue?
this is what you are lokking for laravels queues
I don't believe this existed when I first posted this quesiton. However, Laravel now has this built for it: https://laravel.com/docs/5.6/horizon which is everything I was looking for.

Using ruby and sinatra how can I schedule a script to run (at an unpredictable time) in the future?

I am designing a reminder type app. Somebody enters into a form, for example, "call me at such and such a time on such and such a day in the future to remind me of something".
This is put into a postgres database. Obviously lots of people (hopefully) will be doing this and scheduling different things at different times in the future.
So, my question is how can ensure that my app checks the database for things it has to do at the right time? Can I:
a) should I, when the entry is made, create an automated script to execute at the time necessary to perform the reminder function? If so, how?
b) get my app to check the database every minute, again if so how? This would seem a huge waste of resources.
Sorry I cannot provide any code for this but I have no idea where to begin. all help gratefully received.
Thank you!
You might wanna use a background job framework like Sidekiq. Sidekiq supports scheduled jobs like this:
Notifier.perform_at(a_time_object, message_to_send)
It seems like Sidekiq also works with Sinatra.
For that particular task I prefer whenever https://github.com/javan/whenever

Grails - Time consuming processing in the controller

I currently have a controller that does a bit of heavy lifting processing (bulk csv file processing - cvs files ranging from 150Mb to 400Mb). The CSV files are uploaded to a temporary file location. Processing is done by a service that passes the file location to an APIs from an external jar (basic java API calling - no web service calls or anything). The service method takes about 2-3 times to return and the user has to wait currently for this time for the processing to complete and page to load after submitting a form - not the best user experience.
Grails users who have faced such a problem, what is the best solution to this kind of problem? I am new to Grails and JavaEE and hence this is basically a question on how one would architect such a system and the kind of libraries available for this.
I have googled quite a bit on this. People have responded with JMS, RabbitMQ etc as the solution to similar problems. But these appear to be swapping a fly with a bazooka kind of solution to my noob mind. Your suggestions are very much appreciated.
Thank you.
You can use the Spring #Async annotation on a service method if you want that method to be executed in a different thread. This is the approach I take in my Grails apps, it's dead easy.
There's an example of how to set it up here:
http://tux2323.blogspot.co.uk/2012/05/grails-and-spring-async-annotation.html?m=1
Use the quartz plugin... get the controller to schedule an immediate job (the scheduling is quick and the user will get a response straight away, and the processing will happen in a quartz job which runs in a different thread). Just notify the user when all the work is done (send an email or whatever).
Alternatively, use executor plugin to kick the job off in a new thread. 2.3 will have Async Support which could help here.

creating a pojo/ejb with spring 3 that always runs in the background

I have created apps in the past that would have web pages that would call the persistence layer to get some query results or to insert, delete, etc against a db. However, nothing was left running in the background except for the persistence layer. Now I need to develop an app that has an process that is always running in the background, which is waiting for messages to come thru a zeromq messaging system (cannot change this at this point). I am a little lost as to how to setup the object so that it can always be running and yet I can control or query the results from the object.
Is there any tutorial/examples that covers this configuration?
Thanks,
You could use some kind of timer, to start a method every second to look at a specific ressource and process the input taken from that.
If you use Spring than you could have a look at the #Scheduled annotation.
If your input is some kind of java method invokation, than have a look at the java.util.concurrent Package, and concurrent programming at all. -- But be aware of the fact, that there are some restictions one creating own Threads in an EJB environment.

Resources