<commit_before><?php

/**
 * Start a decider worker.
 *
 * @package amazon-bundle
 * @copyright (c) 2013 Underground Elephant
 * @author <NAME>
 *
 * Copyright 2013 Underground Elephant
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Uecode\Bundle\AmazonBundle\Command\SimpleWorkflow;

//use Symfony\Component\Console\Command\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\Container;

// Amazon Classes
use \AmazonSWF;
use \CFRuntime;

class DeciderWorkerCommand extends ContainerAwareCommand
{
	protected function configure() {
		$this
			->setName('ue:aws:simpleworkflow:deciderworker')
			->setDescription('Start a decider worker which will poll amazon for a decision task. The "domain" and "name" arguments are required and they both specify config params at uecode.amazon.simpleworkflow.domains.[<domain>].workflows.[<name>]. The rest of the config values can be overridden w/ their respective options to this command.')
			->addArgument(
				'domain',
				InputArgument::REQUIRED,
				'The SWF workflow domain.'
			)
			->addArgument(
				'name',
				InputArgument::REQUIRED,
				'The SWF workflow name.'
			)
			->addOption(
				'workflow_version',
				null,
				InputOption::VALUE_REQUIRED,
				'The SWF workflow version.'
			)
			->addOption(
				'taskList',
				null,
				InputOption::VALUE_REQUIRED,
				'The SWF workflow taskList'
			)
			->addOption(
				'event_namespace',
				null,
				InputOption::VALUE_REQUIRED,
				'Where your event classes are located'
			)
			->addOption(
				'activity_event_namespace',
				null,
				InputOption::VALUE_REQUIRED,
				'Where your activity classes are located'
			);
	}

	protected function execute(InputInterface $input, OutputInterface $output) {
		$container = $this->getApplication()->getKernel()->getContainer();

		$logger = $container->get('logger');

		try {
			// default values
			$version = null;
			$taskList = null;
			$eventNamespace = null;
			$activityNamespace = null;

			$logger->log(
				'info',
				'About to start decider worker'
			);

			$amazonFactory = $container->get('uecode.amazon')->getFactory('ue');

			$domain = $input->getArgument('domain');
			$name = $input->getArgument('name');

			$cfg = $amazonFactory->getConfig()->get('simpleworkflow');

			foreach ($cfg['domains'] as $dk => $dv) {
				if ($dk == $domain) {
					foreach ($dv['workflows'] as $kk => $kv) {
						if ($kk == $name) {
							$version = $kv['version'];
							$taskList = $kv['task_list'];
							$eventNamespace = $kv['history_event_namespace'];
							$activityNamespace = $kv['history_activity_event_namespace'];
						}
					}
				}
			}

			// allow config to be overridden by passed values.
			$version = $input->getOption('workflow_version') ?: $version;
			$taskList = $input->getOption('taskList') ?: $taskList;
			$eventNamespace = $input->getOption('event_namespace') ?: $eventNamespace;
			$activityNamespace = $input->getOption('activity_event_namespace') ?: $activityNamespace;

			$logger->log(
				'info',
				'Starting decider worker',
				array(
					'domain' => $domain,
					'name' => $name,
					'version' => $version,
					'taskList' => $taskList,
					'eventNamespace' => $eventNamespace,
					'activityNamespace' => $activityNamespace
				)
			);

			$swf = $amazonFactory->build('AmazonSWF', array('domain' => $domain), $container);
			$decider = $swf->loadDecider($name, $version, $taskList, $eventNamespace, $activityNamespace);

			// note that run() will sit in a loop while(true).
			$decider->run();

			$output->writeln('done');
			$logger->log(
				'info',
				'Decider worker ended'
			);
		} catch (\Exception $e) {<commit_msg>decider command takes taskList as a param<commit_after><?php

/**
 * Start a decider worker.
 *
 * @package amazon-bundle
 * @copyright (c) 2013 Underground Elephant
 * @author <NAME>
 *
 * Copyright 2013 Underground Elephant
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Uecode\Bundle\AmazonBundle\Command\SimpleWorkflow;

//use Symfony\Component\Console\Command\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\Container;

// Amazon Classes
use \AmazonSWF;
use \CFRuntime;

class DeciderWorkerCommand extends ContainerAwareCommand
{
	protected function configure() {
		$this
			->setName('ue:aws:simpleworkflow:deciderworker')
			->setDescription('Start a decider worker which will poll amazon for a decision task. The "domain" and "name" arguments are required and they both specify config params at uecode.amazon.simpleworkflow.domains.[<domain>].workflows.[<name>]. The rest of the config values can be overridden w/ their respective options to this command.')
			->addArgument(
				'domain',
				InputArgument::REQUIRED,
				'The SWF workflow domain.'
			)
			->addArgument(
				'name',
				InputArgument::REQUIRED,
				'The SWF workflow name.'
			)
			->addArgument(
				'task_list',
				null,
				InputArgument::REQUIRED,
				'The SWF taskList to poll on.'
			)
			->addOption(
				'workflow_version',
				null,
				InputOption::VALUE_REQUIRED,
				'The SWF workflow version.'
			)
			->addOption(
				'event_namespace',
				null,
				InputOption::VALUE_REQUIRED,
				'Where your event classes are located'
			)
			->addOption(
				'activity_event_namespace',
				null,
				InputOption::VALUE_REQUIRED,
				'Where your activity classes are located'
			);
	}

	protected function execute(InputInterface $input, OutputInterface $output) {
		$container = $this->getApplication()->getKernel()->getContainer();

		$logger = $container->get('logger');

		try {
			// default values
			$version = null;
			$taskList = null;
			$eventNamespace = null;
			$activityNamespace = null;

			$logger->log(
				'info',
				'About to start decider worker'
			);

			$amazonFactory = $container->get('uecode.amazon')->getFactory('ue');

			$domain = $input->getArgument('domain');
			$name = $input->getArgument('name');
			$taskList = $input->getArgument('task_list');

			$cfg = $amazonFactory->getConfig()->get('simpleworkflow');

			foreach ($cfg['domains'] as $dk => $dv) {
				if ($dk == $domain) {
					foreach ($dv['workflows'] as $kk => $kv) {
						if ($kk == $name) {
							$version = $kv['version'];
							$eventNamespace = $kv['history_event_namespace'];
							$activityNamespace = $kv['history_activity_event_namespace'];
						}
					}
				}
			}

			// allow config to be overridden by passed values.
			$version = $input->getOption('workflow_version') ?: $version;
			$eventNamespace = $input->getOption('event_namespace') ?: $eventNamespace;
			$activityNamespace = $input->getOption('activity_event_namespace') ?: $activityNamespace;

			if (empty($domain)
			 || empty($name)
			 || empty($version)
			 || empty($taskList)
			 || empty($eventNamespace)
			 || empty($activityNamespace)) {
				throw new \Exception('Decider/workflow is misconfigured.');
			}

			$logger->log(
				'info',
				'Starting decider worker',
				array(
					'domain' => $domain,
					'name' => $name,
					'version' => $version,
					'taskList' => $taskList,
					'eventNamespace' => $eventNamespace,
					'activityNamespace' => $activityNamespace
				)
			);

			$swf = $amazonFactory->build('AmazonSWF', array('domain' => $domain), $container);
			$decider = $swf->loadDecider($name, $version, $taskList, $eventNamespace, $activityNamespace);

			// note that run() will sit in a loop while(true).
			$decider->run();

			$output->writeln('done');
			$logger->log(
				'info',
				'Decider worker ended'
			);
		} catch (\Exception $e) {
{'fraction_non_alphanumeric': 0.13452617627567925, 'fraction_numerical': 0.0026507620941020544, 'mean_word_length': 3.7733263046916186, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1795013', 'n_tokens_mistral': 3224, 'n_tokens_neox': 2658, 'n_words': 713}