1111import java .io .IOException ;
1212import java .util .logging .Level ;
1313import java .util .logging .Logger ;
14+ import java .util .concurrent .atomic .AtomicInteger ;
1415
1516public class BuildScheduler {
1617 private static final Logger LOGGER = Logger .getLogger (BuildScheduler .class .getName ());
18+ private static AtomicInteger counter = new AtomicInteger (1 );
19+
1720 public static void scheduleBuild (final Queue .BuildableItem bi ) {
1821 try (ACLContext _ = ACL .as (ACL .SYSTEM )) {
1922 final DockerSwarmLabelAssignmentAction action = createLabelAssignmentAction (bi .task .getDisplayName ());
@@ -35,18 +38,20 @@ public static void scheduleBuild(final Queue.BuildableItem bi) {
3538 }
3639
3740 private static DockerSwarmLabelAssignmentAction createLabelAssignmentAction (String taskName ) {
41+
3842 try {
3943 Thread .sleep (5 , 10 );
4044 } catch (final InterruptedException e ) {
4145 LOGGER .log (Level .INFO ,"couldn't add agent" , e );
4246 }
4347 taskName = taskName .replaceAll ("[^a-zA-Z0-9]" , "_" );
44- if (taskName .length () > 15 ) {
45- taskName = taskName .substring (taskName .length () - 15 );
48+ if (taskName .length () > 30 ) {
49+ taskName = taskName .substring (taskName .length () - 30 );
4650 }
4751 String truncatedTime = Long .toString (System .nanoTime ());
48- truncatedTime = truncatedTime .substring (truncatedTime .length () - 5 );
49-
50- return new DockerSwarmLabelAssignmentAction ("agent-" + taskName + "-" + truncatedTime );
52+ truncatedTime = truncatedTime .substring (truncatedTime .length () - 10 );
53+
54+ return new DockerSwarmLabelAssignmentAction ("agent-" + taskName + "-" +
55+ truncatedTime + "-" + BuildScheduler .counter .incrementAndGet ());
5156 }
5257}
0 commit comments