Handle not connecting at start.

We previously assumed that we would connect to gearman immediately and be able
to send a SET_CLIENT_ID packet; that would raise an exception and stop any
further gearman processing.  Instead, don't assume we can send that packet,
and also, do send it immediately after reconnecting.

Also, lower the retry delay from 3 second to 2.  I don't think we'll mind
Jenkins being in a tighter loop because it probably won't be doing anything else.

Change-Id: Id585726e23076ad22e2935173995db2bdadf9974
This commit is contained in:
James E. Blair 2013-06-05 17:21:45 -07:00
parent 7a8d940c4b
commit 61e47a1e8b

View File

@ -155,11 +155,16 @@ public class MyGearmanWorkerImpl implements GearmanSessionEventHandler {
LOG.info("Starting reconnect for " + session.toString());
try {
session.initSession(ioAvailable, this);
if (id != null) {
sendToAll(new GearmanPacketImpl(GearmanPacketMagic.REQ,
GearmanPacketType.SET_CLIENT_ID,
ByteUtils.toUTF8Bytes(id)));
}
// this will cause a grab-job event
functionRegistry.setUpdated(true);
} catch (IOException e) {
try {
Thread.sleep(3000);
Thread.sleep(2000);
} catch (InterruptedException e1) {
}
}
@ -425,8 +430,11 @@ public class MyGearmanWorkerImpl implements GearmanSessionEventHandler {
throw new IllegalArgumentException("Worker ID may not be null");
}
this.id = id;
sendToAll(new GearmanPacketImpl(GearmanPacketMagic.REQ,
GearmanPacketType.SET_CLIENT_ID, ByteUtils.toUTF8Bytes(id)));
if (session.isInitialized()) {
sendToAll(new GearmanPacketImpl(GearmanPacketMagic.REQ,
GearmanPacketType.SET_CLIENT_ID,
ByteUtils.toUTF8Bytes(id)));
}
}
public String getWorkerID() {