Created
March 20, 2018 06:13
-
-
Save seiriosPlus/4143b4907f01eb9206cbbd9dbf59bddd to your computer and use it in GitHub Desktop.
Revisions
-
seiriosPlus created this gist
Mar 20, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ func chunk_split(chunks []Chunk, lim int) [][]chunk_slices { var chunk []Chunk chunk_slices := make([][]Chunk, 0, len(chunks)/lim+1) for len(chunks) >= lim { chunk, chunks = chunks[:lim], chunks[lim:] chunk_slices = append(chunk_slices, chunk) } if len(buf) > 0 { chunk_slices = append(chunk_slices, chunks[:len(chunks)]) } return chunk_slices } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ func partition(chunks []Chunk, chunksPerTask int) []taskEntry { // generate uniq id across job using nanosecond + randint + counter // FIXME(typhoonzero): this is a workaround, use uuid randStart := rand.Int() timestamp := time.Now().Nanosecond() if chunksPerTask <= 0 { chunksPerTask = 1 } var result []taskEntry chunk_slices := chunk_split(chunks, chunksPerTask) for i,c := range chunk_slices { var cur taskEntry cur.Task.Meta.ID = timestamp + randStart + (i + 1) cur.Task.Chunks = chunk_slices[i] result = append(result, cur) } return result }