@@ -300,7 +300,33 @@ func main() {
300300 // Real work.
301301 // If run as part of a Batch Job or Fleet it just prints the message to stdout.
302302 // Otherwise run as part of an App and start the HTTP server to processing incoming requests
303- if IsJob () {
303+ if IsFleet () {
304+ // Fleet tasks run to completion
305+
306+ fleetName := os .Getenv ("CE_FLEET_NAME" )
307+
308+ sleep := os .Getenv ("SLEEP" )
309+ sleepDuration := 0
310+ if sleep != "" {
311+ sleepDuration , _ = strconv .Atoi (sleep )
312+ }
313+
314+ // Check whether the job should sleep a while before printing the helloworld statement
315+ if sleepDuration > 0 {
316+ Debug (false , "Sleeping %ds" , sleepDuration )
317+ time .Sleep (time .Duration (sleepDuration ) * time .Second )
318+ }
319+
320+ fmt .Printf ("Hello from helloworld! I'm a task of fleet: %s! Task Index: %s, Task ID: %s\n \n " , fleetName , os .Getenv ("CE_TASK_INDEX" ), os .Getenv ("CE_TASK_ID" ))
321+ PrintMessage (os .Stdout , os .Getenv ("SHOW" ) == "" )
322+
323+ // If the 'CRASH' or 'FAIL' env vars are set then crash!
324+ if os .Getenv ("CRASH" ) != "" || os .Getenv ("FAIL" ) != "" {
325+ fmt .Printf ("Crashing..." )
326+ os .Exit (1 )
327+ }
328+
329+ } else if IsJob () {
304330 // Jobs can be either started in 'task' mode and run to completion or in 'daemon' mode which
305331 jobMode := os .Getenv ("JOB_MODE" )
306332
@@ -335,32 +361,6 @@ func main() {
335361 break
336362 }
337363 }
338- } else if IsFleet () {
339- // Fleet tasks run to completion
340-
341- fleetName := os .Getenv ("CE_FLEET_NAME" )
342-
343- sleep := os .Getenv ("SLEEP" )
344- sleepDuration := 0
345- if sleep != "" {
346- sleepDuration , _ = strconv .Atoi (sleep )
347- }
348-
349- // Check whether the job should sleep a while before printing the helloworld statement
350- if sleepDuration > 0 {
351- Debug (false , "Sleeping %ds" , sleepDuration )
352- time .Sleep (time .Duration (sleepDuration ) * time .Second )
353- }
354-
355- fmt .Printf ("Hello from helloworld! I'm a task of fleet: %s! Task Index: %s, Task ID: %s\n \n " , fleetName , os .Getenv ("CE_TASK_INDEX" ), os .Getenv ("CE_TASK_ID" ))
356- PrintMessage (os .Stdout , os .Getenv ("SHOW" ) == "" )
357-
358- // If the 'CRASH' or 'FAIL' env vars are set then crash!
359- if os .Getenv ("CRASH" ) != "" || os .Getenv ("FAIL" ) != "" {
360- fmt .Printf ("Crashing..." )
361- os .Exit (1 )
362- }
363-
364364 } else {
365365 srv := & http.Server {Addr : ":8080" }
366366
0 commit comments