Search in sources :

Example 1 with SingularityWebhook

use of com.hubspot.singularity.SingularityWebhook in project Singularity by HubSpot.

the class WebhookManager method requestHistoryEvent.

// TODO consider caching the list of hooks (at the expense of needing to refresh the cache and not
// immediately make some webhooks)
@Override
public void requestHistoryEvent(SingularityRequestHistory requestUpdate) {
    for (SingularityWebhook webhook : getActiveWebhooksByType(WebhookType.REQUEST)) {
        final String enqueuePath = getEnqueuePathForRequestUpdate(webhook.getId(), requestUpdate);
        save(enqueuePath, requestUpdate, requestHistoryTranscoder);
    }
}
Also used : SingularityWebhook(com.hubspot.singularity.SingularityWebhook)

Example 2 with SingularityWebhook

use of com.hubspot.singularity.SingularityWebhook in project Singularity by HubSpot.

the class WebhookManager method deployHistoryEvent.

@Override
public void deployHistoryEvent(SingularityDeployUpdate deployUpdate) {
    for (SingularityWebhook webhook : getActiveWebhooksByType(WebhookType.DEPLOY)) {
        final String enqueuePath = getEnqueuePathForDeployUpdate(webhook.getId(), deployUpdate);
        save(enqueuePath, deployUpdate, deployWebhookTranscoder);
    }
}
Also used : SingularityWebhook(com.hubspot.singularity.SingularityWebhook)

Example 3 with SingularityWebhook

use of com.hubspot.singularity.SingularityWebhook in project Singularity by HubSpot.

the class WebhookManager method taskHistoryUpdateEvent.

@Override
public void taskHistoryUpdateEvent(SingularityTaskHistoryUpdate taskUpdate) {
    for (SingularityWebhook webhook : getActiveWebhooksByType(WebhookType.TASK)) {
        final String enqueuePath = getEnqueuePathForTaskUpdate(webhook.getId(), taskUpdate);
        save(enqueuePath, taskUpdate, taskHistoryUpdateTranscoder);
    }
}
Also used : SingularityWebhook(com.hubspot.singularity.SingularityWebhook)

Example 4 with SingularityWebhook

use of com.hubspot.singularity.SingularityWebhook in project Singularity by HubSpot.

the class SingularityWebhookSender method checkWebhooks.

public void checkWebhooks() {
    final long start = System.currentTimeMillis();
    final List<SingularityWebhook> webhooks = webhookManager.getActiveWebhooks();
    if (webhooks.isEmpty()) {
        return;
    }
    int taskUpdates = 0;
    int requestUpdates = 0;
    int deployUpdates = 0;
    List<CompletableFuture<Response>> webhookFutures = new ArrayList<>();
    for (SingularityWebhook webhook : webhooks) {
        switch(webhook.getType()) {
            case TASK:
                taskUpdates += checkTaskUpdates(webhook, webhookFutures);
                break;
            case REQUEST:
                requestUpdates += checkRequestUpdates(webhook, webhookFutures);
                break;
            case DEPLOY:
                deployUpdates += checkDeployUpdates(webhook, webhookFutures);
                break;
            default:
                break;
        }
    }
    CompletableFutures.allOf(webhookFutures).exceptionally((t) -> {
        LOG.error("Exception in webhook", t);
        return null;
    });
    LOG.info("Sent {} task, {} request, and {} deploy updates for {} webhooks in {}", taskUpdates, requestUpdates, deployUpdates, webhooks.size(), JavaUtils.duration(start));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SingularityWebhook(com.hubspot.singularity.SingularityWebhook) ArrayList(java.util.ArrayList)

Aggregations

SingularityWebhook (com.hubspot.singularity.SingularityWebhook)4 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1