poller process in activiti - java

I have created an activiti process for the lifecycle of an email which passes many service tasks.
Now I have another process that polls emails from a queue and starts the new activiti email process everytime a new email is polled.
the poller process should never stop polling.
I understand that an activiti process(the poller) is not meant to never end?
I tried to make this work, but when an error occurs in 1 of my activiti email processes, the poller process also stops.
How should this be made?
I am thinking about the REST API?
(I create my poller outside of activiti, and I call the api everytime a new email process needs to be started?)
I really want to keep everything within my activiti explorer, but is this possible?

You can set the timer for the polling process. such tat polling can happen at periodic intervals.
Do check about Activiti timer events. The timer can also be added at the process level, its not just for tasks.

Related

JMS with Consumer performing long running process (10mins)

I have a scenario in Spring boot applications - where I will be getting requests from other applications via REST "Run Process" Service and these will be placed on MQ queues. Then consumers will process one by one and the consumer calls another REST "Initiate Request" service which will take around 10mins to get a response back. I am looking for ideas/solutions where I can fire the REST "Initiate Request" service and forget then stop the consumer. Once "Initiate Request" completes its processing, the system will send an event notification indicating this process has completed/failed. Based on this I would like to proceed with the next Queue item. Is there a way to Stop and Start consumers based on notification to avoid long-running threads? If you have come across this problem, let me know how you have resolved it.
There are other solutions like
Consumers to persist the data to database and process row by row.
Using webflux we can avoid JMS-Consumer thread but not consumer calling REST

How to check if data is getting processed in Spring Integration or sitting idle

This is regarding Spring integration(SI) Application where in my case there are many endpoints present. So usually when data enters into this application, it takes about 60 sec to get processed completly.
I am now trying to build shutdown mechanism for this application which will do following things :-
It will first stop ingestion layer endpoint (in my case a kafka listener), so that no more message will enter into application
It will then wait for 60 secs before getting shutdown. So that existing message gets processed.
But this wait time is hardcoded and i want to check if application is processing any data or not. If yes then wait for 30 secs and then check again. If no data are getting processed then shutdown the application.
Kindly let me know if there are any ways which i can check if data are present in any of the SI endpoints.
There is no hooks like this in the out-of-the-box components. And probably it is even not possible to implement that since all the component in the framework are stateless.
Now tell me, please, what makes you think that you need to implement your own shutdown mechanism. Why the regular ApplicationContext.close() is not enough for you?
See more about lifecycle in the docs: https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-factory-nature
With that on board the framework indeed stops inbound endpoints first to not let external data to enter the application while it is in the shutdown state. Then it stops all other internal endpoints to stop processing their incoming messages. But all on-the-fly messages are still processed. The application context is not done if there is something executing.
If that still not enough for you, I'd suggest something like an AtomicInteger activeCount as a global bean. You incrementAndGet() it when the message is emitted by your mentioned Kafka listener. When you done processing the message in the end of flow your call its decrementAndGet(). And when your custom shutdown function is in progress, you just check the number of that activeCount.get() to be sure that it is 0 to kill your process gracefully.
But again: we don't need all of that because the standard ApplicationContext.close() covers us.

Running a continuous background task in Play 2.4.2 server

I'm creating a web application that displays incoming events as strings onto the web browser. The events should be coming in from a listener that I have defined in another part of the program. These events will be emitted through a socket to the client side.
The problem: I need to keep the listener continually running in order to receive messages. The listener is essentially one block of code that's something like listener.run(), and it doesn't terminate. Right now, I am making a separate thread that runs this block of code and I have configured Global settings to run the thread on application startup.
I don't want my task to stop and start every time I refresh the page. How can I make the listener run right when the server starts?
Look at the Scheduling asynchronous tasks at the end of the doc: https://www.playframework.com/documentation/2.4.x/JavaAkka

Is it possible to create a GAE cron job on a local GAE server?

This link says that GAE does not support cron jobs on the development server. So what are my other options?
I need to send emails out to users when a deadline on their account is reached.
Use a local cron service, and whrite a script which uses curl or wget to call your cron handler.
Another way is to use enqueued tasks.
At start-up, your web app could query all users and enqueue a task for each one if there is a deadline, with the task's ETA set to that deadline.
When a task fires, it checks to see if the deadline is "now" or earlier. If so, then execute your deadline processing code. In all cases, examine (the next?) deadline for that user. If one exists then enqueue another task....
Of course, your dev web app server must be running continuously for the enqueued tasks to fire; they are all lost on shut-down.
Any help?

Triggering an Asynchronous process in Java

I have a web application that takes in user requests and puts them into a MYSQL database. Now a typical user request needs to be serviced by following a workflow that would take significant time to complete. To address this i have an asynchronous processor that keeps listening to the MYSQL table.
I have noticed that polling the MYSQL table on an infinite loop results in a spike in CPU usage on the box my application is deployed to that often renders the box unusable.
I know that making the asynchronous process sleep for 'some' time whenever there aren't any active requests in the MYSQL database is an option but i would like to keep that as a last resort.
Making this process synchronous is not an option because of the time the workflow involved in servicing a single request takes and also because there is a need to decouple the processing from the front end to allow the back end to evolve.
I would like to know if there is any smart way to trigger off the asynchronous process so that i can avoid the CPU usage spike and still get optimum response time from the asynchronous processor.
Any advices would be appreciated.
Thanks
p1ng
An option would be to store the request in the database AND send some kind of event in you system (eg. JMS message, or by using java.util.concurrent constructs). The process that reads and executes the command can then be awaken by this signal, go fetch the data in the database and process it as usual.
This way, you wouldn't waste CPU cycles polling not-yet-available data, and you would be more reactive due to the absence of polling delay.
You can make your asynchronous process read from a TCP socket or something similar. The asynchronous process should just wait blocking on i/o. Then from your primary process you can send a message over to the asynchronous process once it has updated the table. It may be possible to send the message from a trigger in database too.
I would generally not recommend polling based approach to check the table. What happens when you have to poll for different events at different schedules? If you envision need for multiple events in the future, I would suggest looking into message queues for asynchronous tasks.
But if you have to go with polling based approach for now - I don't fully understand your reasoning against letting the asynchronous process sleep for some time? Why would you want your process to consume all the CPU resources doing nothing but running in an infinite loop? Why not have your async process run at specific intervals? You can make this polling interval configurable.
You can use the FutureTask Java API to do that. See that blog entry.
Or perhaps just new Thread(YourRunnable).start(), and make some state variable in YourRunnable to know if your task is finished or not.

Categories