44 "context"
55 "fmt"
66 "log"
7- "sort"
87 "strconv"
98 "strings"
109 "time"
@@ -131,6 +130,7 @@ func (a JobsAPI) Restart(id string, timeout time.Duration) error {
131130// Create creates a job on the workspace given the job settings
132131func (a JobsAPI ) Create (jobSettings JobSettings ) (Job , error ) {
133132 var job Job
133+ jobSettings .sortTasksByKey ()
134134 err := a .client .Post (a .context , "/jobs/create" , jobSettings , & job )
135135 return job , err
136136}
@@ -156,6 +156,9 @@ func (a JobsAPI) Read(id string) (job Job, err error) {
156156 err = wrapMissingJobError (a .client .Get (a .context , "/jobs/get" , map [string ]int64 {
157157 "job_id" : jobID ,
158158 }, & job ), id )
159+ if job .Settings != nil {
160+ job .Settings .sortTasksByKey ()
161+ }
159162 return
160163}
161164
@@ -288,9 +291,6 @@ func ResourceJob() *schema.Resource {
288291 if err != nil {
289292 return err
290293 }
291- sort .Slice (js .Tasks , func (i , j int ) bool {
292- return js .Tasks [i ].TaskKey < js .Tasks [j ].TaskKey
293- })
294294 if js .isMultiTask () {
295295 ctx = context .WithValue (ctx , common .Api , common .API_2_1 )
296296 }
@@ -311,9 +311,6 @@ func ResourceJob() *schema.Resource {
311311 if err != nil {
312312 return err
313313 }
314- sort .Slice (job .Settings .Tasks , func (i , j int ) bool {
315- return job .Settings .Tasks [i ].TaskKey < job .Settings .Tasks [j ].TaskKey
316- })
317314 d .Set ("url" , c .FormatURL ("#job/" , d .Id ()))
318315 return common .StructToData (* job .Settings , jobSchema , d )
319316 },
0 commit comments