<commit_before>package grails.plugin.uberjobs

import grails.transaction.Transactional

@Transactional
class UberWorkerService extends AbstractUberService {

    def uberQueueService
    def uberWorkerMetaService

    def createWorkersFromConfig() {
        // iterate over workers configurations
        config.workers.each { poolName, config ->
            List queueNames
            // check queue configuration, should be a list, a single string or a closure that is returning a list
            if (config.queueNames in List) {
                queueNames = config.queueNames
            } else if (config.queueNames instanceof Closure) {
                def closureResult = config.queueNames.call()
                assert closureResult in List, "$poolName's queueNames closure has not returned a list!"
                queueNames = closureResult
            } else if (config.queueNames in String) {
                queueNames = [config.queueNames]
            } else {
                throw new RuntimeException("queueNames of $poolName must be a List, Closure (returning a list) or a String. ${config.queueNames.class.simpleName} is not allowed!")
            }
            // start the appropiate amount of workers
            config.workers.times { index ->
                start(poolName, index, queueNames)
            }
        }
    }

    def start(poolName, index, queueNames){
        UberWorkerMeta workerMeta = UberWorkerMeta.findByPoolNameAndHostnameAndIndex(poolName, hostName, index)
        if(!workerMeta){
            workerMeta = createWorker(poolName, index, queueNames)
        } else if(config.workers.update){
            // TODO: UPDATE
        }
        //TODO: start the actual Thread
    }

    def createWorker(String poolName, int index, List queueNames) {
        def queues = []
        queueNames.each { String name
            queues << uberQueueService.findOrCreate(name)
        }
        uberWorkerMetaService.create(poolName, index, queues)
    }


    String getName(poolName, index) {
        "$hostName-$poolName-$index"
    }
}
<commit_msg>optimized worker creation a bit mir<commit_after>package grails.plugin.uberjobs

import grails.transaction.Transactional

@Transactional
class UberWorkerService extends AbstractUberService {

    def uberQueueService
    def uberWorkerMetaService

    def createWorkersFromConfig() {
        // iterate over workers configurations
        config.workers.each { poolName, config ->
            List queueNames
            // check queue configuration, should be a list, a single string or a closure that is returning a list
            if (config.queueNames in List) {
                queueNames = config.queueNames
            } else if (config.queueNames instanceof Closure) {
                def closureResult = config.queueNames.call()
                assert closureResult in List, "$poolName's queueNames closure has not returned a list!"
                queueNames = closureResult
            } else if (config.queueNames in String) {
                queueNames = [config.queueNames]
            } else {
                throw new RuntimeException("queueNames of $poolName must be a List, Closure (returning a list) or a String. ${config.queueNames.class.simpleName} is not allowed!")
            }
            def queues = []
            queueNames.each { String name
                queues << uberQueueService.findOrCreate(name)
            }
            // start the appropiate amount of workers
            config.workers.times { index ->
                start(poolName, index, queues)
            }
        }
    }

    def start(poolName, index, queues){
        UberWorkerMeta workerMeta = UberWorkerMeta.findByPoolNameAndHostnameAndIndex(poolName, hostName, index)
        if(!workerMeta){
            workerMeta = createWorker(poolName, index, queues)
        } else if(config.workers.update){
            // TODO: UPDATE
        }
        //TODO: start the actual Thread
    }

    def createWorker(String poolName, int index, List queues) {
        uberWorkerMetaService.create(poolName, index, queues)
    }


    String getName(poolName, index) {
        "$hostName-$poolName-$index"
    }
}

{'fraction_non_alphanumeric': 0.07527393997141496, 'fraction_numerical': 0.0, 'mean_word_length': 2.1666666666666665, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '375466', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1040, 'n_words': 311}