# Path: automlk/worker_text.py
# def worker_text_loop():
#     """
#     periodically pool the receiver queue for a search job
# 
#     :return:
#     """
#     while True:
#         heart_beep('worker_text', '')
#         # check the list of datasets
#         for ts in get_textset_list():
#             if ts.status != 'completed':
#                 heart_beep('worker_text', {'textset_id': ts.textset_id, 'textset_name': ts.name})
#                 log.info('searching textset %s' % ts.textset_id)
# 
#                 # read textset
#                 textset = get_textset(ts.textset_id)
#                 set_key_store('textset:%s:status' % ts.textset_id, 'searching')
# 
#                 # import text
#                 with open(textset.filename, 'r') as f:
#                     text = f.readlines()
# 
#                 # calculate models
#                 for conf in space_textset_bow:
#                     pickle.dump(model_bow(text, conf), open(text_model_filename(ts.textset_id, 'bow', conf), 'wb'))
# 
#                 for conf in space_textset_w2v:
#                     pickle.dump(model_word2vec(text, conf), open(text_model_filename(ts.textset_id, 'w2v', conf), 'wb'))
# 
#                 for conf in space_textset_d2v:
#                     pickle.dump(model_doc2vec(text, conf), open(text_model_filename(ts.textset_id, 'd2v', conf), 'wb'))
# 
#                 # update status to completed
#                 set_key_store('textset:%s:status' % ts.textset_id, 'completed')
# 
# Path: automlk/context.py
# def get_data_folder():
#     """
#     retrieves root folder from 'automlk.json' configuration file
#     :return: storage folder name of the data
#     """
#     return get_config()['data']


import logging
import sys
import os
from automlk.worker_text import worker_text_loop
from automlk.context import get_data_folder

logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s [%(module)s %(lineno)3d] %(message)s',
                    handlers=[
                        logging.FileHandler(get_data_folder() + '/worker_text.log'),
                        logging.StreamHandler()
                    ])

logging.info('starting worker text')

while True:
    try:

# Path: automlk/worker_text.py
# def worker_text_loop():
#     """
#     periodically pool the receiver queue for a search job
# 
#     :return:
#     """
#     while True:
#         heart_beep('worker_text', '')
#         # check the list of datasets
#         for ts in get_textset_list():
#             if ts.status != 'completed':
#                 heart_beep('worker_text', {'textset_id': ts.textset_id, 'textset_name': ts.name})
#                 log.info('searching textset %s' % ts.textset_id)
# 
#                 # read textset
#                 textset = get_textset(ts.textset_id)
#                 set_key_store('textset:%s:status' % ts.textset_id, 'searching')
# 
#                 # import text
#                 with open(textset.filename, 'r') as f:
#                     text = f.readlines()
# 
#                 # calculate models
#                 for conf in space_textset_bow:
#                     pickle.dump(model_bow(text, conf), open(text_model_filename(ts.textset_id, 'bow', conf), 'wb'))
# 
#                 for conf in space_textset_w2v:
#                     pickle.dump(model_word2vec(text, conf), open(text_model_filename(ts.textset_id, 'w2v', conf), 'wb'))
# 
#                 for conf in space_textset_d2v:
#                     pickle.dump(model_doc2vec(text, conf), open(text_model_filename(ts.textset_id, 'd2v', conf), 'wb'))
# 
#                 # update status to completed
#                 set_key_store('textset:%s:status' % ts.textset_id, 'completed')
# 
# Path: automlk/context.py
# def get_data_folder():
#     """
#     retrieves root folder from 'automlk.json' configuration file
#     :return: storage folder name of the data
#     """
#     return get_config()['data']


# Path: run/run_worker_text.py
import logging
import sys
import os
from automlk.worker_text import worker_text_loop
from automlk.context import get_data_folder


logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s [%(module)s %(lineno)3d] %(message)s',
                    handlers=[
                        logging.FileHandler(get_data_folder() + '/worker_text.log'),
                        logging.StreamHandler()
                    ])

logging.info('starting worker text')

while True:
    try:

        worker_text_loop()