Rev 35547 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.dao.event;import com.spice.profitmandi.dao.service.solr.FofoSolr;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Value;import org.springframework.context.ApplicationListener;import org.springframework.context.annotation.Profile;import org.springframework.context.event.ContextRefreshedEvent;import org.springframework.stereotype.Component;/*** Triggers a full Solr sync on application startup.* Ensures data consistency after application restarts.* Only active in production environment.*/@Component@Profile("scheduled")public class SolrStartupSync implements ApplicationListener<ContextRefreshedEvent> {private static final Logger logger = LoggerFactory.getLogger(SolrStartupSync.class);private boolean executed = false;@Value("${prod:false}")private boolean isProd;@Autowiredprivate FofoSolr fofoSolr;@Overridepublic void onApplicationEvent(ContextRefreshedEvent event) {// Only execute once (ContextRefreshedEvent may fire multiple times)if (executed) {return;}executed = true;if (!isProd) {logger.info("Skipping Solr startup sync in non-prod environment");return;}logger.info("Application context refreshed - triggering full Solr sync for data consistency");try {fofoSolr.pushData();logger.info("Full Solr sync completed successfully on startup");} catch (Exception e) {logger.error("Full Solr sync failed on startup", e);}}}