0

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?

Muatik
  • 4,011
  • 10
  • 39
  • 72

1 Answers1

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.

Community
  • 1
  • 1
Gulliva
  • 488
  • 2
  • 10
  • 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