<commit_before>import os
from os import path
import subprocess
import shutil
from datetime import datetime
import jsondate as json

from simplekv.fs import FilesystemStore

import logging

from mytardis_ngs_ingestor.illumina import run_info

from mytardis_ngs_ingestor.illumina.run_info import get_run_id_from_path, \
    get_sample_project_mapping
from mytardis_ngs_ingestor.illumina import fastqc
from mytardis_ngs_ingestor import illumina_uploader
from mytardis_ngs_ingestor.utils import batch
from mytardis_ngs_ingestor.illumina.fastqc import get_fastqc_output_directory

# status enum
CREATED = 'created'  # record created, no action taken on task yet
RUNNING = 'running'
COMPLETE = 'complete'
ERROR = 'error'


class Current(object):
    _singleton = None

    def __init__(self):
        self.task = None

    def __new__(cls, *args, **kwargs):
        if not cls._singleton:
            cls._singleton = super(Current, cls).__new__(cls, *args, **kwargs)
        return cls._singleton


class ProcessingTask(object):
    def __init__(self, run_id, task_name, status,
                 db=None,
                 timestamp=None,
                 last_failure_notify_time=None,
                 info=None):
        self.timestamp = timestamp or datetime.now()
        self.last_failure_notify_time = last_failure_notify_time
        self.run_id = run_id
        self.task_name = task_name
        self.status = status  # running / complete / error
        self.info = info or {}
        self._db = db  # underscore = not serialized

    # def as_dict(self):
    #     return {'timestamp': self.timestamp,
    #             'run_id': self.run_id,
    #             'task_name': self.task_name,
    #             'status': self.status,
    #             'info': self.info}
    #
    #     # return self.__dict__

    def is_complete(self):
        return self.status == COMPLETE

    def is_pending(self):
        return self.status != COMPLETE

    def is_running(self):
        return self.status == RUNNING

    def is_failed(self):
        return self.status == ERROR

    def __str__(self):
        return json.dumps(self.__dict__) + '\n'


class TaskDb(FilesystemStore):
    def __init__(self, basedir, default_type, db_id=None, db_name='tasks'):
        self.dbpath = path.join(basedir, db_name)

        if not path.exists(self.dbpath):
            os.mkdir(path.join(basedir, db_name))

        super(TaskDb, self).__init__(self.dbpath)

        self.db_id = db_id
        self.default_type = default_type

    def _put(self, key, data):
        import jsondate as json

        if not isinstance(data, dict):
            data = dict(data.__dict__)
            # any key starting with underscore isn't serialized
            for k in data.keys():<commit_msg>autoprocessing: minor refactor, use correct variable for tasks db path.<commit_after>import os
from os import path
import subprocess
import shutil
from datetime import datetime
import jsondate as json

from simplekv.fs import FilesystemStore

import logging

from mytardis_ngs_ingestor.illumina import run_info

from mytardis_ngs_ingestor.illumina.run_info import get_run_id_from_path, \
    get_sample_project_mapping
from mytardis_ngs_ingestor.illumina import fastqc
from mytardis_ngs_ingestor import illumina_uploader
from mytardis_ngs_ingestor.utils import batch
from mytardis_ngs_ingestor.illumina.fastqc import get_fastqc_output_directory

# status enum
CREATED = 'created'  # record created, no action taken on task yet
RUNNING = 'running'
COMPLETE = 'complete'
ERROR = 'error'


class Current(object):
    _singleton = None

    def __init__(self):
        self.task = None

    def __new__(cls, *args, **kwargs):
        if not cls._singleton:
            cls._singleton = super(Current, cls).__new__(cls, *args, **kwargs)
        return cls._singleton


class ProcessingTask(object):
    def __init__(self, run_id, task_name, status,
                 db=None,
                 timestamp=None,
                 last_failure_notify_time=None,
                 info=None):
        self.timestamp = timestamp or datetime.now()
        self.last_failure_notify_time = last_failure_notify_time
        self.run_id = run_id
        self.task_name = task_name
        self.status = status  # running / complete / error
        self.info = info or {}
        self._db = db  # underscore = not serialized

    # def as_dict(self):
    #     return {'timestamp': self.timestamp,
    #             'run_id': self.run_id,
    #             'task_name': self.task_name,
    #             'status': self.status,
    #             'info': self.info}
    #
    #     # return self.__dict__

    def is_complete(self):
        return self.status == COMPLETE

    def is_pending(self):
        return self.status != COMPLETE

    def is_running(self):
        return self.status == RUNNING

    def is_failed(self):
        return self.status == ERROR

    def __str__(self):
        return json.dumps(self.__dict__) + '\n'


class TaskDb(FilesystemStore):
    def __init__(self, basedir, default_type, db_id=None, db_name='tasks'):
        self.dbpath = path.join(basedir, db_name)

        if not path.exists(self.dbpath):
            os.mkdir(self.dbpath)

        super(TaskDb, self).__init__(self.dbpath)

        self.db_id = db_id
        self.default_type = default_type

    def _put(self, key, data):
        import jsondate as json

        if not isinstance(data, dict):
            data = dict(data.__dict__)
            # any key starting with underscore isn't serialized
            for k in data.keys():
{'fraction_non_alphanumeric': 0.0853352456077447, 'fraction_numerical': 0.0, 'mean_word_length': 2.613341968911917, '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': '6604675', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1697, 'n_words': 427}