Issue
I have a python script needs to be run periodically. At first, I could consider triggering this script via a cronjob task. However, in my case, I have to do this through spring. The solution I am thinking of is writing a scheduled task in my spring app, and then running the python script via command line call. Is this possible in spring?
Solution
Yes this is possible take a look at spring documentation:
https://docs.spring.io/spring/docs/current/spring-framework-reference/html/scheduling.html
You can enableScheduling with the
@EnableScheduling
Annotation. Then you have to add the
@Scheduled(cron="*/5 * * * * MON-FRI")
Annotation to your function. Just start a Process in there which executes the Python script for you. Here is another link where it is explained how to start a python script from java in the console:
How to execute Python script from Java?
Hope that helps you.
Answered By - Gulliva