Define a unique parameter for stop worker.

The stop worker identifies the job that should be stopped by the
unique ID supplied when the job is started.  However, the current
implementation gets the unique ID of the job to cancel from the unique
id of the stop job itself.  This is confusing and possibly erroneous
since it overloads the meaning of a gearman unique id.

Instead, have the stop job interpret the gearman argument as the
unique id of the job to stop.

Change-Id: Ida7a68976d3f764df504aff9afdae81265e0006f
This commit is contained in:
James E. Blair 2013-04-29 13:17:40 -07:00
parent 4e560245c0
commit d3bc4dda56
1 changed files with 8 additions and 9 deletions

View File

@ -53,12 +53,11 @@ public class StopJobWorker extends AbstractGearmanFunction {
*/
@Override
public GearmanJobResult executeFunction() {
// decode the uniqueId from the client
String decodedUniqueId = null;
if (this.uniqueId != null) {
String cancelID = null;
if (this.data != null) {
// decode the data from the client
try {
decodedUniqueId = new String(this.uniqueId, "UTF-8");
cancelID = new String((byte[]) this.data, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
@ -70,19 +69,19 @@ public class StopJobWorker extends AbstractGearmanFunction {
String jobWarningMsg = "";
String jobResultMsg = "";
if (decodedUniqueId.isEmpty() || decodedUniqueId == null){
if (cancelID == null || cancelID.isEmpty()) {
logger.info("---- Client passed in an invalid UUID");
jobFailureMsg = "I need the job Id please";
jobResult = false;
} else {
// Abort running jenkins build that contain matching uuid
jobResult = abortBuild(decodedUniqueId);
jobResult = abortBuild(cancelID);
if (jobResult){
jobResultMsg = "Canceled jenkins build " + decodedUniqueId;
jobResultMsg = "Canceled jenkins build " + cancelID;
} else {
jobFailureMsg = "Could not cancel build " + decodedUniqueId;
jobFailureMsg = "Could not cancel build " + cancelID;
jobResult = false;
}
}