ninjaframework / ninja

Ninja is a full stack web framework for Java. Rock solid, fast and super productive.
http://www.ninjaframework.org
Apache License 2.0
1.91k stars 521 forks source link

Can use @Schedule annotation with @UnitOfWork or @Transactional #736

Closed thibaultmeyer closed 2 years ago

thibaultmeyer commented 2 years ago

This pull request adds support for the use @Schedule with annotations such as @UnitOfWork or @Transactional or more generally a proxy class.

Before

@Singleton
public class TestJob {

    private final TestService testService;

    @Inject
    public TestJob (final TestService testService) {
        this.testService= testService;
    }

    @Schedule(delay = 30, initialDelay = 30, timeUnit = TimeUnit.SECONDS)
    public void every30seconds() {
        runOnTransaction();
    }

    @UnitOfWork
    public void runOnTransaction() {
        testService.doWork();
    }
}

After

@Singleton
public class TestJob {

    private final TestService testService;

    @Inject
    public TestJob (final TestService testService) {
        this.testService= testService;
    }

    @Schedule(delay = 30, initialDelay = 30, timeUnit = TimeUnit.SECONDS)
    @UnitOfWork 
    public void every30seconds() {
        testService.doWork();
    }
}
thibaultmeyer commented 2 years ago

Done + rebase to fix conflict on Changelog.md

@raphaelbauer

raphaelbauer commented 2 years ago

Nice!