package io.trygvis; import io.trygvis.model.Article; import io.trygvis.queue.AsyncService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.List; import java.util.Random; import static org.springframework.transaction.annotation.Propagation.MANDATORY; @Component("createArticle") @Transactional(propagation = MANDATORY) public class CreateArticleCallable implements AsyncService.AsyncCallable { private final Logger log = LoggerFactory.getLogger(getClass()); // @PersistenceContext // private EntityManager entityManager; private Random random = new Random(); public void run(List arguments) throws Exception { log.info("CreateArticeJob.run: BEGIN"); if (random.nextInt() % 3 == 0) { throw new RuntimeException("failing create article"); } Date now = new Date(); log.info("now = {}", now); Article article = new Article(new Date(), null, "title", "body"); // entityManager.persist(article); log.info("CreateArticeJob.run: END"); } }