<commit_before>package de.qaware.oss.cloud.service.process.boundary;

import com.codahale.metrics.annotation.Timed;
import de.qaware.oss.cloud.service.process.domain.ProcessEvent;
import de.qaware.oss.cloud.service.process.domain.ProcessStatusCache;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.json.Json;
import javax.json.JsonObject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;

@ApplicationScoped
@Path("process")
@Produces(MediaType.APPLICATION_JSON)
public class ProcessResource {

    @Inject
    private Logger logger;

    @Inject
    private Event<ProcessEvent> processEvent;

    @Inject
    private ProcessStatusCache statusCache;

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Timed
    public Response process(JsonObject jsonObject) {
        logger.log(Level.INFO, "POST new process {0}", jsonObject);

        ProcessEvent event = ProcessEvent.created(jsonObject);
        processEvent.fire(event);

        return Response.accepted().build();
    }

    @GET
    @Path("/{processId}/status")
    @Timed
    public Response process(@PathParam("processId") String processId) {
        logger.log(Level.INFO, "GET process status for {0}", processId);

        Optional<ProcessEvent.EventType> eventType = statusCache.get(processId);
        ProcessEvent.EventType status = eventType.orElseThrow(NotFoundException::new);

        JsonObject payload = Json.createObjectBuilder()
                .add("processId", processId)
                .add("status", status.name())
                .build();

        return Response.ok(payload).build();
    }
}
<commit_msg>Added async processing for posting resources.<commit_after>package de.qaware.oss.cloud.service.process.boundary;

import com.codahale.metrics.annotation.Timed;
import de.qaware.oss.cloud.service.process.domain.ProcessEvent;
import de.qaware.oss.cloud.service.process.domain.ProcessStatusCache;

import javax.annotation.Resource;
import javax.enterprise.concurrent.ManagedExecutorService;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.json.Json;
import javax.json.JsonObject;
import javax.ws.rs.*;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

@ApplicationScoped
@Path("process")
@Produces(MediaType.APPLICATION_JSON)
public class ProcessResource {

    @Inject
    private Logger logger;

    @Inject
    private Event<ProcessEvent> processEvent;

    @Inject
    private ProcessStatusCache statusCache;

    @Resource
    private ManagedExecutorService executorService;

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Timed
    public void process(@Suspended AsyncResponse response, JsonObject jsonObject) {
        logger.log(Level.INFO, "POST new process {0}", jsonObject);

        response.setTimeout(5, TimeUnit.SECONDS);
        response.setTimeoutHandler((r) -> r.resume(Response.accepted().build()));

        executorService.execute(() -> {
            ProcessEvent event = ProcessEvent.created(jsonObject);
            processEvent.fire(event);
            response.resume(Response.accepted(event).build());
        });
    }

    @GET
    @Path("/{processId}/status")
    @Timed
    public Response process(@PathParam("processId") String processId) {
        logger.log(Level.INFO, "GET process status for {0}", processId);

        Optional<ProcessEvent.EventType> eventType = statusCache.get(processId);
        ProcessEvent.EventType status = eventType.orElseThrow(NotFoundException::new);

        JsonObject payload = Json.createObjectBuilder()
                .add("processId", processId)
                .add("status", status.name())
                .build();

        return Response.ok(payload).build();
    }
}

{'fraction_non_alphanumeric': 0.11457334611697027, 'fraction_numerical': 0.0011984659635666348, 'mean_word_length': 3.758266818700114, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4160078', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1168, 'n_words': 222}