CampaignService
CampaignService
🔧 Method: startCampaign(Long campaignId)
startCampaign(Long campaignId)@Service
public class CampaignService {
@Autowired
private CampaignRepository campaignRepository;
@Autowired
private TransactionTemplateBuilder ttb;
@Autowired
private CampaignExecutionService campaignExecutionService;
@Transactional(rollbackFor = Throwable.class)
public void startCampaign(Long campaignId) {
Campaign campaign = campaignRepository.getSync(campaignId);
Assert.isTrue(campaign.isActive(), "Campaign is not active");
if (campaign.getExecutionType() == CampaignExecutionType.AUTOMATIC) {
if (campaign.getAutomaticCampaignStatus() != AutomaticCampaignStatus.SCHEDULED) {
campaign.setAutomaticCampaignStatus(AutomaticCampaignStatus.SCHEDULED);
}
} else if (campaign.isNotInExecution()) {
CampaignExecution execution = campaignExecutionService.createExecution(campaign);
TransactionUtils.afterTransaction(() -> {
ttb.requiresNew().executeWithoutResult(status ->
campaignExecutionService.runExecution(execution.getId())
);
});
}
}
}📌 Behavior
🔒 Transactional Handling
Last updated
Was this helpful?