-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #369 from HubSpot/move_webhook_to_leader
move webhook processing to leader only
- Loading branch information
Showing
12 changed files
with
80 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 12 additions & 43 deletions
55
...rvice/src/main/java/com/hubspot/singularity/data/history/SingularityHistoryPersister.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,28 @@ | ||
package com.hubspot.singularity.data.history; | ||
|
||
import io.dropwizard.lifecycle.Managed; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.inject.Inject; | ||
import com.hubspot.singularity.config.SingularityConfiguration; | ||
import com.hubspot.singularity.scheduler.SingularityLeaderOnlyPoller; | ||
import com.hubspot.singularity.sentry.SingularityExceptionNotifier; | ||
|
||
@Singleton | ||
public class SingularityHistoryPersister extends SingularityLeaderOnlyPoller implements Managed { | ||
public abstract class SingularityHistoryPersister extends SingularityLeaderOnlyPoller { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(SingularityHistoryPersister.class); | ||
private final SingularityConfiguration configuration; | ||
|
||
private final SingularityTaskHistoryPersister taskPersister; | ||
private final SingularityDeployHistoryPersister deployPersister; | ||
private final SingularityRequestHistoryPersister requestHistoryPersister; | ||
private final SingularityExceptionNotifier exceptionNotifier; | ||
public SingularityHistoryPersister(SingularityConfiguration configuration) { | ||
super(configuration.getPersistHistoryEverySeconds(), TimeUnit.SECONDS); | ||
|
||
@Inject | ||
public SingularityHistoryPersister(SingularityExceptionNotifier exceptionNotifier, SingularityTaskHistoryPersister taskPersister, | ||
SingularityRequestHistoryPersister requestHistoryPersister, SingularityDeployHistoryPersister deployPersister, SingularityConfiguration configuration) { | ||
super(configuration.getPersistHistoryEverySeconds(), TimeUnit.SECONDS, configuration.getDatabaseConfiguration().isPresent()); | ||
this.configuration = configuration; | ||
} | ||
|
||
this.taskPersister = taskPersister; | ||
this.deployPersister = deployPersister; | ||
this.exceptionNotifier = exceptionNotifier; | ||
this.requestHistoryPersister = requestHistoryPersister; | ||
@Override | ||
protected boolean abortsOnError() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void runActionOnPoll() { | ||
try { | ||
taskPersister.checkInactiveTaskIds(); | ||
} catch (Throwable t) { | ||
exceptionNotifier.notify(t); | ||
LOG.error("While persisting task history", t); | ||
} | ||
try { | ||
deployPersister.checkInactiveDeploys(); | ||
} catch (Throwable t) { | ||
exceptionNotifier.notify(t); | ||
LOG.error("While persisting deploy history", t); | ||
} | ||
try { | ||
requestHistoryPersister.checkRequestHistory(); | ||
} catch (Throwable t) { | ||
exceptionNotifier.notify(t); | ||
LOG.error("While persisting request history", t); | ||
} | ||
protected boolean isEnabled() { | ||
return configuration.getDatabaseConfiguration().isPresent(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 10 additions & 37 deletions
47
SingularityService/src/main/java/com/hubspot/singularity/hooks/SingularityWebhookPoller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,35 @@ | ||
package com.hubspot.singularity.hooks; | ||
|
||
import io.dropwizard.lifecycle.Managed; | ||
|
||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.common.util.concurrent.MoreExecutors; | ||
import com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
import com.google.inject.Inject; | ||
import com.hubspot.mesos.JavaUtils; | ||
import com.hubspot.singularity.config.SingularityConfiguration; | ||
import com.hubspot.singularity.scheduler.SingularityLeaderOnlyPoller; | ||
import com.hubspot.singularity.sentry.SingularityExceptionNotifier; | ||
|
||
@Singleton | ||
public class SingularityWebhookPoller implements Managed { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(SingularityWebhookPoller.class); | ||
public class SingularityWebhookPoller extends SingularityLeaderOnlyPoller { | ||
|
||
private final SingularityWebhookSender webhookSender; | ||
private final SingularityExceptionNotifier exceptionNotifier; | ||
private final SingularityConfiguration configuration; | ||
private final ScheduledExecutorService executorService; | ||
|
||
@Inject | ||
public SingularityWebhookPoller(SingularityWebhookSender webhookSender, SingularityExceptionNotifier exceptionNotifier, SingularityConfiguration configuration) { | ||
this.webhookSender = webhookSender; | ||
this.configuration = configuration; | ||
this.exceptionNotifier = exceptionNotifier; | ||
super(configuration.getCheckWebhooksEveryMillis(), TimeUnit.MILLISECONDS); | ||
|
||
this.executorService = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setNameFormat("SingularityWebhookSender-%d").build()); | ||
this.webhookSender = webhookSender; | ||
} | ||
|
||
@Override | ||
public void start() { | ||
LOG.info("Starting a webhookPoller that executes webhooks every {}", JavaUtils.durationFromMillis(configuration.getCheckWebhooksEveryMillis())); | ||
|
||
executorService.scheduleAtFixedRate(new Runnable() { | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
webhookSender.checkWebhooks(); | ||
} catch (Throwable t) { | ||
LOG.error("Caught an unexpected exception while checking webhooks", t); | ||
exceptionNotifier.notify(t); | ||
} | ||
} | ||
}, configuration.getCheckWebhooksEveryMillis(), configuration.getCheckWebhooksEveryMillis(), TimeUnit.MILLISECONDS); | ||
public void runActionOnPoll() { | ||
webhookSender.checkWebhooks(); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
MoreExecutors.shutdownAndAwaitTermination(executorService, 1, TimeUnit.SECONDS); | ||
protected boolean abortsOnError() { | ||
return false; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.