com.transferwise.tasks.entrypoints.EntryPointsService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tw-tasks-core Show documentation
Show all versions of tw-tasks-core Show documentation
Transferwise Tasks Executor - Fire and forget until Alert.
package com.transferwise.tasks.entrypoints;
import com.transferwise.common.context.TwContext;
import com.transferwise.common.context.UnitOfWorkManager;
import java.util.function.Supplier;
import org.springframework.beans.factory.annotation.Autowired;
public class EntryPointsService implements IEntryPointsService {
@Autowired
private UnitOfWorkManager unitOfWorkManager;
@Autowired
private MdcService mdcService;
@Override
public T continueOrCreate(String group, String name, Supplier supplier) {
if (TwContext.current().isEntryPoint()) {
return mdcService.with(() -> supplier.get());
}
return createEntrypoint(group, name, supplier);
}
@Override
public T createEntrypoint(String group, String name, Supplier supplier) {
return unitOfWorkManager.createEntryPoint(group, name).toContext().execute(mdcService.with(() -> supplier));
}
}