package com.atlassian.bitbucket.mesh.git.builder;

import io.grpc.Context;
import io.grpc.Deadline;

import javax.annotation.Nonnull;
import java.time.Instant;
import java.util.concurrent.TimeUnit;

public class DeadlineGitProcessBuilderConfigurer implements GitProcessBuilderConfigurer {

    @Override
    public void configure(@Nonnull GitProcessBuilder builder) {
        Deadline deadline = Context.current().getDeadline();
        if (deadline != null) {
            builder.withDeadline(Instant.now().plusMillis(deadline.timeRemaining(TimeUnit.MILLISECONDS)));
        }
    }
}
