package io.trygvis; import io.trygvis.model.*; import io.trygvis.queue.*; import org.slf4j.*; import org.springframework.stereotype.*; import org.springframework.transaction.annotation.*; import java.util.*; import static org.springframework.transaction.annotation.Propagation.*; @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"); } }