Skip to content

Rendering a lot of tasks goes terribly wrong (aka "too much to do") #10

Open
@skatkov

Description

Thank you for great library.

I have noticed an issue, that it has issue rendering many tasks. Here is a reproduction.

You can change number of tasks that this code generates, if you go as low as 2 or 3 - it all works as expected. But 10 or more - and output is cut off and even that part of content never gets correctly updated with status.

package main

import (
	"fmt"
	"math/rand"
	"time"

	"github.com/fumeapp/taskin"
)

type Library struct {
	Name string
}

func main() {
	libraries := generateLibraries(20)
	runners := NewLibraryDownloader(libraries)

	runners.Run()
}

func generateLibraries(count int) []Library {
	libraries := make([]Library, count)
	for i := 0; i < count; i++ {
		libraries[i] = Library{
			Name: fmt.Sprintf("Library%d", i+1),
		}
	}
	return libraries
}

func NewLibraryDownloader(libraries []Library) taskin.Runners {
	var tasks []taskin.Task

	for _, library := range libraries {
		tasks = append(tasks, createTasksForLibrary(library))
	}

	return taskin.New(tasks, taskin.Defaults)
}

func createTasksForLibrary(library Library) taskin.Task {
	return taskin.Task{
		Title: fmt.Sprintf("Process %s", library.Name),
		Tasks: taskin.Tasks{
			{
				Title: "Download",
				Task:  createSimulatedTask(500, 2000),
			},
			{
				Title: "Unarchive",
				Task:  createSimulatedTask(200, 1000),
			},
			{
				Title: "Process",
				Task:  createSimulatedTask(300, 1500),
			},
		},
	}
}

func createSimulatedTask(minDuration, maxDuration int) func(*taskin.Task) error {
	return func(_ *taskin.Task) error {
		duration := time.Duration(rand.Intn(maxDuration-minDuration)+minDuration) * time.Millisecond
		time.Sleep(duration)

		return nil
	}
}

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions