<commit_before><?php
/**
 * Yiiq - background job queue manager for Yii
 *
 * This file contains job runner class.
 *
 * @author  <NAME> <<EMAIL>>
 * @package yiiq.commands
 */

namespace Yiiq\jobs;

use Yiiq\Yiiq;
use Yiiq\base\Component;

/**
 * Job runner class.
 *
 * @author  <NAME> <<EMAIL>>
 */
class Runner extends Component
{
    /**
     * @var Job
     */
    protected $job = null;

    public function __construct(Yiiq $owner, Job $job)
    {
        parent::__construct($owner);
        $this->job = $job;
    }

    public function run()
    {
        $job = $this->job;

        // Try to fork process.
        $childPid = pcntl_fork();

        // Force reconnect to redis for parent and child due to bug in PhpRedis
        // (https://github.com/nicolasff/phpredis/issues/474).
        \Yii::app()->redis->getClient(true);

        if ($childPid > 0) {
            return $childPid;
        } elseif ($childPid < 0) {
            // If we're failed to fork process, restore job and exit.
            \Yii::app()->yiiq->restore($job->id);

            return;
        }

        // We are child - get our pid.
        $childPid = posix_getpid();

        $this->owner->setProcessTitle(
            'job',
            $job->metadata->queue,
            'initializing'
        );

        \Yii::trace('Starting job '.$job->metadata->queue.':'.$job->id.' ('.$job->metadata->class.')...');
        $this->owner->setProcessTitle(
            'job',
            $job->metadata->queue,
            'executing '.$job->metadata->id.' ('.$job->metadata->class.')'
        );

        $job->status->markAsStarted($childPid);

        $payload = $job->payload;
        $result = $payload->execute($job->metadata->args);

        if ($job->metadata->type === Yiiq::TYPE_REPEATABLE) {
            $job->status->markAsStopped();
        } else {
            $job->metadata->delete();
            $job->result->save($result);
            $job->status->markAsCompleted();
        }

        \Yii::trace('Job '.$job->metadata->queue.':'.$job->metadata->id.' done.');
<commit_msg>Removed unnecessary code<commit_after><?php
/**
 * Yiiq - background job queue manager for Yii
 *
 * This file contains job runner class.
 *
 * @author  <NAME> <<EMAIL>>
 * @package yiiq.commands
 */

namespace Yiiq\jobs;

use Yiiq\Yiiq;
use Yiiq\base\Component;

/**
 * Job runner class.
 *
 * @author  <NAME> <<EMAIL>>
 */
class Runner extends Component
{
    /**
     * @var Job
     */
    protected $job = null;

    public function __construct(Yiiq $owner, Job $job)
    {
        parent::__construct($owner);
        $this->job = $job;
    }

    public function run()
    {
        $job = $this->job;

        // Try to fork process.
        $childPid = pcntl_fork();

        // Force reconnect to redis for parent and child due to bug in PhpRedis
        // (https://github.com/nicolasff/phpredis/issues/474).
        \Yii::app()->redis->getClient(true);

        if ($childPid > 0) {
            return $childPid;
        } elseif ($childPid < 0) {
            // If we're failed to fork process, restore job and exit.
            \Yii::app()->yiiq->restore($job->id);

            return;
        }

        // We are child - get our pid.
        $childPid = posix_getpid();
        
        $metadata = $job->metadata;
        $status = $job->status;
        
        $this->owner->setProcessTitle(
            'job',
            $metadata->queue,
            'executing '.$metadata->id.' ('.$metadata->class.')'
        );

        \Yii::trace('Starting job '.$metadata->queue.':'.$job->id.' ('.$metadata->class.')...');

        $status->markAsStarted($childPid);

        $payload = $job->payload;
        $result = $payload->execute($metadata->args);

        if ($metadata->type === Yiiq::TYPE_REPEATABLE) {
            $status->markAsStopped();
        } else {
            $metadata->delete();
            $job->result->save($result);
            $status->markAsCompleted();
        }

        \Yii::trace('Job '.$metadata->queue.':'.$job->id.' done.');

{'fraction_non_alphanumeric': 0.17443868739205526, 'fraction_numerical': 0.002467308166790032, 'mean_word_length': 1.8874643874643875, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 90, 'https://': 2, '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': '1958673', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1263, 'n_words': 268}