Java Code Examples for hudson.slaves.AbstractCloudComputer#getIdleStartMilliseconds()

The following examples show how to use hudson.slaves.AbstractCloudComputer#getIdleStartMilliseconds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DockerCloudRetentionStrategy.java    From yet-another-docker-plugin with MIT License 6 votes vote down vote up
/**
 * While x-stream serialisation buggy, copy implementation.
 */
@Override
@GuardedBy("hudson.model.Queue.lock")
public long check(final AbstractCloudComputer c) {
    final AbstractCloudSlave computerNode = c.getNode();
    if (c.isIdle() && computerNode != null) {
        final long idleMilliseconds = System.currentTimeMillis() - c.getIdleStartMilliseconds();
        if (idleMilliseconds > MINUTES.toMillis(idleMinutes)) {
            LOG.info("Disconnecting {}, after {} min timeout.", c.getName(), idleMinutes);
            try {
                computerNode.terminate();
            } catch (InterruptedException | IOException e) {
                LOG.warn("Failed to terminate {}", c.getName(), e);
            }
        }
    }
    return 1;
}
 
Example 2
Source File: DockerOnceRetentionStrategy.java    From yet-another-docker-plugin with MIT License 6 votes vote down vote up
@Override
@GuardedBy("hudson.model.Queue.lock")
public long check(final AbstractCloudComputer acc) {
    // When the slave is idle we should disable accepting tasks and check to see if it is already trying to
    // terminate. If it's not already trying to terminate then lets terminate manually.
    if (acc.isIdle() && !disabled) {
        final long idleMilliseconds = System.currentTimeMillis() - acc.getIdleStartMilliseconds();
        if (idleMilliseconds > TimeUnit2.MINUTES.toMillis(idleMinutes)) {
            LOG.debug("Disconnecting {}", acc.getName());
            done(acc);
        }
    }

    // Return one because we want to check every minute if idle.
    return 1;
}