<commit_before>async = require "async"
moment = require "moment"
log = require('printit')
    prefix: null
    date: true
importer = require "./importer"

class KonnectorPoller

    start: ->
        @prepareNextCheck()

    prepareNextCheck: ->
        # Every week we check for new data for each konnector
        now = moment()
        nextUpdate = now.clone()
        nextUpdate = now.add(1, 'w')
        format = "DD/MM/YYYY [at] HH:mm:ss"
        msg = "Next import of konnectors on #{nextUpdate.format(format)}"
        log.info msg
        @timeout = setTimeout(
            () =>
                @checkAllAccesses()
            , nextUpdate - moment())

    checkAllAccesses: ->
        log.info "Checking new entries for all konnectors..."
        importer (err) =>
            if err?
                console.log "An error occurred during fetching -- #{err}"
        log.info "All konnectors fetched."
        @prepareNextCheck()


module.exports = new KonnectorPoller
<commit_msg>refactoring<commit_after>async = require "async"
moment = require "moment"
log = require('printit')
    prefix: null
    date: true
importer = require "./importer"

class KonnectorPoller

    start: ->
        @prepareNextCheck()

    prepareNextCheck: ->
        # Every week we check for new data for each konnector
        now = moment()
        nextUpdate = now.clone()
        nextUpdate = now.add(1, 'w')
        format = "DD/MM/YYYY [at] HH:mm:ss"
        msg = "Next import of konnectors on #{nextUpdate.format(format)}"
        log.info msg
        setTimeout =>
            @checkAllAccesses()
        , nextUpdate - moment()

    checkAllAccesses: ->
        log.info "Checking new entries for all konnectors..."
        importer (err) =>
            if err?
                log.info "An error occurred during fetching -- #{err}"
            log.info "All konnectors fetched."
            @prepareNextCheck()

module.exports = new KonnectorPoller

{'fraction_non_alphanumeric': 0.10974358974358975, 'fraction_numerical': 0.0010256410256410256, 'mean_word_length': 2.091917591125198, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1346390', 'n_tokens_mistral': 570, 'n_tokens_neox': 555, 'n_words': 163}