<commit_before>package task_launcher

import (
	"fmt"

	"github.com/Sirupsen/logrus"
	"github.com/emc-advanced-dev/layerx/layerx-core/lxstate"
	"github.com/emc-advanced-dev/layerx/layerx-core/lxtypes"
	"github.com/emc-advanced-dev/layerx/layerx-core/rpi_messenger"
	"github.com/emc-advanced-dev/pkg/errors"
	"sync"
	"time"
)

type TaskLauncher struct {
	state *lxstate.State
}

func NewTaskLauncher(state *lxstate.State) *TaskLauncher {
	return &TaskLauncher{
		state: state,
	}
}

//temp buffer to prevent us from trying to re-launch tasks too quickly
var tasksMarkedForLaunch = make(map[string]string)
var markedLock sync.RWMutex

func (tl *TaskLauncher) LaunchStagedTasks() error {
	stagingTasks, err := tl.state.StagingTaskPool.GetTasks()
	if err != nil {
		return errors.New("retrieving staging tasks", err)
	}

	nodeTaskMap := make(map[string][]*lxtypes.Task)
MarkTasks:
	for _, task := range stagingTasks {
		//don't attempt to launch this task twice if the launch request has already been
		//sent to an rpi in the last 1 minutes (TODO: reevaluate this)
		markedLock.RLock()
		for marked := range tasksMarkedForLaunch {
			if task.TaskId == marked {
				markedLock.RUnlock()
				continue MarkTasks
			}<commit_msg>dont wait to relaunch a task if it's checkpointed<commit_after>package task_launcher

import (
	"fmt"

	"github.com/Sirupsen/logrus"
	"github.com/emc-advanced-dev/layerx/layerx-core/lxstate"
	"github.com/emc-advanced-dev/layerx/layerx-core/lxtypes"
	"github.com/emc-advanced-dev/layerx/layerx-core/rpi_messenger"
	"github.com/emc-advanced-dev/pkg/errors"
	"sync"
	"time"
)

type TaskLauncher struct {
	state *lxstate.State
}

func NewTaskLauncher(state *lxstate.State) *TaskLauncher {
	return &TaskLauncher{
		state: state,
	}
}

//temp buffer to prevent us from trying to re-launch tasks too quickly
var tasksMarkedForLaunch = make(map[string]string)
var markedLock sync.RWMutex

func (tl *TaskLauncher) LaunchStagedTasks() error {
	stagingTasks, err := tl.state.StagingTaskPool.GetTasks()
	if err != nil {
		return errors.New("retrieving staging tasks", err)
	}

	nodeTaskMap := make(map[string][]*lxtypes.Task)
MarkTasks:
	for _, task := range stagingTasks {
		//don't attempt to launch this task twice if the launch request has already been
		//sent to an rpi in the last 1 minutes (TODO: reevaluate this)
		markedLock.RLock()
		for marked := range tasksMarkedForLaunch {
			if task.TaskId == marked && !task.Checkpointed {
				markedLock.RUnlock()
				continue MarkTasks
			}
{'fraction_non_alphanumeric': 0.11390887290167866, 'fraction_numerical': 0.0007993605115907274, 'mean_word_length': 4.465065502183406, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3422052', 'n_tokens_mistral': 945, 'n_tokens_neox': 869, 'n_words': 213}