<commit_before>import sys

from boto.swf.layer1 import Layer1
from flowy import logger, MagicBind
from flowy.scanner import Scanner
from flowy.spec import ActivitySpecCollector, TaskSpec, WorkflowSpecCollector
from flowy.swf.poller import ActivityPoller, DecisionPoller
from flowy.swf.scheduler import AsyncActivityScheduler
from flowy.swf.spec import ActivitySpec as RemoteActivitySpec
from flowy.swf.spec import WorkflowSpec as RemoteWorkflowSpec
from flowy.swf.starter import WorkflowStarter
from flowy.worker import SingleThreadedWorker


def start_activity_worker(domain, task_list,
                          layer1=None,
                          reg_remote=True,
                          loop=-1,
                          package=None,
                          ignore=None):
    swf_client = _get_client(layer1, domain)
    Spec = TaskSpec
    if reg_remote:
        Spec = RemoteActivitySpec
    scanner = Scanner(ActivitySpecCollector(Spec, swf_client))
    scanner.scan_activities(package=package, ignore=ignore, level=1)
    poller = ActivityPoller(swf_client, task_list)
    worker = SingleThreadedWorker(poller)
    not_registered = scanner.register(worker)
    if not_registered:
        logger.error(
            'Not all activities could be regestered: %r', not_registered
        )
        sys.exit(1)
    try:
        worker.run_forever(loop)
    except KeyboardInterrupt:
        pass


def start_workflow_worker(domain, task_list,
                          layer1=None,
                          reg_remote=True,
                          loop=-1,
                          package=None,
                          ignore=None):
    swf_client = _get_client(layer1, domain)
    Spec = TaskSpec
    if reg_remote:
        Spec = RemoteWorkflowSpec
    scanner = Scanner(WorkflowSpecCollector(Spec, swf_client))
    scanner.scan_workflows(package=package, ignore=ignore, level=1)
    poller = DecisionPoller(swf_client, task_list)
    worker = SingleThreadedWorker(poller)
    not_registered = scanner.register(worker)
    if not_registered:
        logger.error(
            'Not all workflows could be regestered: %r', not_registered
        )
        sys.exit(1)
    try:
        worker.run_forever(loop)
    except KeyboardInterrupt:
        pass


def async_scheduler(domain, layer1=None):
    return AsyncActivityScheduler(client=_get_client(layer1, domain))


def workflow_starter(domain, name, version,
                     task_list=None, decision_duration=None,
                     workflow_duration=None, layer1=None):
    client = _get_client(layer1, domain)
    return WorkflowStarter(
        name=name,
        version=version,
        client=client,
        task_list=task_list,
        decision_duration=decision_duration,
        workflow_duration=workflow_duration
    )


def _get_client(layer1, domain):
    if layer1 is None:
        layer1 = Layer1()
    return MagicBind(layer1, domain=str(domain))<commit_msg>Garden<commit_after>import sys

from boto.swf.layer1 import Layer1
from flowy import logger, MagicBind
from flowy.scanner import Scanner
from flowy.spec import ActivitySpecCollector, TaskSpec, WorkflowSpecCollector
from flowy.swf.poller import ActivityPoller, DecisionPoller
from flowy.swf.scheduler import AsyncActivityScheduler
from flowy.swf.spec import ActivitySpec as RemoteActivitySpec
from flowy.swf.spec import WorkflowSpec as RemoteWorkflowSpec
from flowy.swf.starter import WorkflowStarter
from flowy.worker import SingleThreadedWorker


def start_activity_worker(domain, task_list,
                          layer1=None,
                          reg_remote=True,
                          loop=-1,
                          package=None,
                          ignore=None):
    swf_client = _get_client(layer1, domain)
    Spec = TaskSpec
    if reg_remote:
        Spec = RemoteActivitySpec
    scanner = Scanner(ActivitySpecCollector(Spec, swf_client))
    scanner.scan_activities(package=package, ignore=ignore, level=1)
    poller = ActivityPoller(swf_client, task_list)
    worker = SingleThreadedWorker(poller)
    not_registered = scanner.register(worker)
    if not_registered:
        logger.error(
            'Not all activities could be regestered: %r', not_registered
        )
        sys.exit(1)
    try:
        worker.run_forever(loop)
    except KeyboardInterrupt:
        pass


def start_workflow_worker(domain, task_list,
                          layer1=None,
                          reg_remote=True,
                          loop=-1,
                          package=None,
                          ignore=None):
    swf_client = _get_client(layer1, domain)
    Spec = TaskSpec
    if reg_remote:
        Spec = RemoteWorkflowSpec
    scanner = Scanner(WorkflowSpecCollector(Spec, swf_client))
    scanner.scan_workflows(package=package, ignore=ignore, level=1)
    poller = DecisionPoller(swf_client, task_list)
    worker = SingleThreadedWorker(poller)
    not_registered = scanner.register(worker)
    if not_registered:
        logger.error(
            'Not all workflows could be regestered: %r', not_registered
        )
        sys.exit(1)
    try:
        worker.run_forever(loop)
    except KeyboardInterrupt:
        pass


def async_scheduler(domain, layer1=None):
    return AsyncActivityScheduler(client=_get_client(layer1, domain))


def workflow_starter(domain, name, version,
                     task_list=None,
                     decision_duration=None,
                     workflow_duration=None,
                     layer1=None):
    client = _get_client(layer1, domain)
    return WorkflowStarter(
        name=name,
        version=version,
        client=client,
        task_list=task_list,
        decision_duration=decision_duration,
        workflow_duration=workflow_duration
    )


def _get_client(layer1, domain):
    if layer1 is None:
        layer1 = Layer1()
    return MagicBind(layer1, domain=str(domain))
{'fraction_non_alphanumeric': 0.06896551724137931, 'fraction_numerical': 0.007064760302775442, 'mean_word_length': 2.503830288744844, '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': '6780717', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1681, 'n_words': 361}