<commit_before>package org.ossim.omar.stager

import org.ossim.omar.core.Repository
import org.ossim.omar.StagerJob
import org.ossim.omar.core.HttpStatusMessage
import java.util.concurrent.Executors
import java.util.concurrent.Callable
import java.lang.management.ManagementFactory
import static groovyx.gpars.GParsPool.withPool

class StagerService
{
  static transactional = true
  def dataManagerService
  def grailsApplication
  def sessionFactory

  def runStager(Repository repository)
  {

    repository.scanStartDate = new Date()
    repository.scanEndDate = null
    repository.save()

    StagerJob.triggerNow( [baseDir: repository.baseDir] )
  }

  def cleanUpGorm()
  {
    def session = sessionFactory.currentSession
    session.flush()
    session.clear()
  }

  def popAndAddStagerQueueItem()
  {
    def result = 0
    def nthreads = grailsApplication.config.stager.queue.threads ?: 4
    try
    {
      StagerQueueItem.withTransaction {
        def records = StagerQueueItem.list( cache: false,
            sort: "dateCreated",
            max: 100,
            order: "desc" )
        records.each { record ->
          record.status = "indexing"
          record.save()
        }
        withPool() {
          records.collectParallel { item ->
            def msg = new HttpStatusMessage();
            dataManagerService.add( msg, [datainfo: item.dataInfo] )
          }

        }<commit_msg>Trying to try catch some errors occuring on windows somewhere<commit_after>package org.ossim.omar.stager

import org.ossim.omar.core.Repository
import org.ossim.omar.StagerJob
import org.ossim.omar.core.HttpStatusMessage
import java.util.concurrent.Executors
import java.util.concurrent.Callable
import java.lang.management.ManagementFactory
import static groovyx.gpars.GParsPool.withPool

class StagerService
{
  static transactional = true
  def dataManagerService
  def grailsApplication
  def sessionFactory

  def runStager(Repository repository)
  {

    repository.scanStartDate = new Date()
    repository.scanEndDate = null
    repository.save()

    StagerJob.triggerNow( [baseDir: repository.baseDir] )
  }

  def cleanUpGorm()
  {
    def session = sessionFactory.currentSession
    session.flush()
    session.clear()
  }

  def popAndAddStagerQueueItem()
  {
    def result = 0
    def nthreads = grailsApplication.config.stager.queue.threads ?: 4
    try
    {
      StagerQueueItem.withTransaction {
        def records=[];

        try{
         records = StagerQueueItem.list( cache: false,
                  sort: "dateCreated",
                  max: 100,
                  order: "desc" )

        }
        catch(def e)
        {
          cleanUpGorm()
        }
        try{
          records.each { record ->
            record.status = "indexing"
            record.save()
          }
        }
        catch(def e)
        {
          cleanUpGorm()
        }
        withPool() {
          records.collectParallel { item ->
            def msg = new HttpStatusMessage();
            dataManagerService.add( msg, [datainfo: item.dataInfo] )
          }
        }
{'fraction_non_alphanumeric': 0.08698453608247422, 'fraction_numerical': 0.0032216494845360823, 'mean_word_length': 2.349514563106796, 'pattern_counts': {'":': 0, '<': 3, '<?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': '833683', 'n_tokens_mistral': 919, 'n_tokens_neox': 891, 'n_words': 188}