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?
Asked
Active
Viewed 2,663 times
1 Answers
3
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.
-
thanks, I am trying to find the real path of the script located in resource path. resource/some.py. my application as a .jar file is deployed onto a tomcat server. – Muatik Jan 23 '17 at 09:26
-
As a jar or as war? Is it a spring boot app or is it a tomcat where you deploy the war/jar file? http://stackoverflow.com/questions/4340653/file-path-to-resource-in-our-war-web-inf-folder – Gulliva Jan 23 '17 at 09:42