Issue
I have a rest service that is supposed to call a function using @Scheduled. The other functions in MyService
work as intended locally and in live, just not the scheduled function. Any ideas on what I am missing here that would cause it to fail only in live?
class="lang-java prettyprint-override">@Configuration
@EnableScheduling
@EnableAsync
@ComponentScan(basePackages = "elsewhere.yyy.yyy")
public class ApplicationConfiguration {
}
@RestController
public class MyController {
@Autowired
MyService service;
}
@Service
public class MyService {
@Async
@Scheduled(fixedRate = 30000, initialDelay = 10000)
public void myTask() {
// Do stuff...
}
}
I turned on debug logging, but am seeing no org.springframework.scheduling.*
logs, my theory should be that spring just isn't seeing @Scheduled
for some reason and is thus not running it, but it is working perfectly fine locally! My other theory is that @Async
might be causing an unexpected interaction, but it doesn't make sense to me that it would cause the function to disappear in live only... The good(?) news is that is consistently not working in live and consistently working locally.
I'm using Spring Boot version 2.5.1
Solution
The problem was caused by an ID-10T error. //Do Stuff...
early on looks for a file that may or may not be there, and short circuits as intended when the file isn't there. The file was provided and the silent short circuit in a live environment made it appear as if the scheduled task was simply never running. The issue was that I provided the file to the incorrect subdirectory, putting said file into the correct directory solved the issue.
Answered By - pwilson
Answer Checked By - Timothy Miller (JavaFixing Admin)