<commit_before><?php

namespace App\Jobs;

use App\Torrent;
use App\RedisStore;
use Illuminate\Bus\Queueable;
use App\Contracts\TorrentContract;
use Illuminate\Queue\SerializesModels;
use App\Exceptions\CopyFailedException;
use Illuminate\Support\Facades\Storage;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class CopyFile implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $torrentId;

    public $torrent;

    public function __construct($torrentId)
    {
        $this->torrentId = $torrentId;
    }

    public function handle()
    {
        $this->torrent = $this->getTorrent();
        if ($this->torrent->isStillDownloading()) {
            $this->torrent->markShouldCopy();
            $this->tryAgainIn(1);
            return;
        }

        $this->torrent->markCopying();

        $maxTries = config('transcopy.max_tries', 1);
        $tryCount = 0;

        while ($tryCount < $maxTries) {
            try {
                $this->copyTorrent();
                break;
            } catch (\Exception $e) {
                $tryCount = $tryCount + 1;
                $this->torrent->markRetry($tryCount);
                \Log::error($e->getMessage());
            }
        }

        if ($tryCount >= $maxTries) {
            $this->torrent->markFailed();
            throw new CopyFailedException($this->torrent->name);
        }

        $this->torrent->markCopied();
    }

    protected function copyTorrent()
    {
        if ($this->torrent->isDirectory()) {

            return $this->copyDirectory($this->torrent);
        }

        return $this->copyFile($this->torrent->getFullPath(), $this->torrent->getBasename());
    }

    protected function copyDirectory($directory)
    {
        $directory->findFiles()->each(function ($entry) {
            $this->copyFile($entry['fullpath'], $entry['path']);<commit_msg>Added some more log info for copied files<commit_after><?php

namespace App\Jobs;

use App\Torrent;
use App\RedisStore;
use Illuminate\Bus\Queueable;
use App\Contracts\TorrentContract;
use Illuminate\Queue\SerializesModels;
use App\Exceptions\CopyFailedException;
use Illuminate\Support\Facades\Storage;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class CopyFile implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $torrentId;

    public $torrent;

    public function __construct($torrentId)
    {
        $this->torrentId = $torrentId;
    }

    public function handle()
    {
        $this->torrent = $this->getTorrent();
        if ($this->torrent->isStillDownloading()) {
            $this->torrent->markShouldCopy();
            $this->tryAgainIn(1);
            return;
        }

        $start = now();

        $this->torrent->markCopying();

        $maxTries = config('transcopy.max_tries', 1);
        $tryCount = 0;

        while ($tryCount < $maxTries) {
            try {
                $this->copyTorrent();
                break;
            } catch (\Exception $e) {
                $tryCount = $tryCount + 1;
                $this->torrent->markRetry($tryCount);
                \Log::error($e->getMessage());
            }
        }

        if ($tryCount >= $maxTries) {
            $this->torrent->markFailed();
            throw new CopyFailedException($this->torrent->name);
        }

        $this->torrent->markCopied();
        $end = now();
        $speed = floor(($this->torrent->size / 1048576) / ($end->diffInSeconds($start)));
        \Log::info('Copied file in ' . $end->diffInMinutes($start) . 'minutes (' . $speed . 'mb/s');
    }

    protected function copyTorrent()
    {
        if ($this->torrent->isDirectory()) {

            return $this->copyDirectory($this->torrent);
        }

        return $this->copyFile($this->torrent->getFullPath(), $this->torrent->getBasename());
    }

    protected function copyDirectory($directory)
    {
        $directory->findFiles()->each(function ($entry) {
            $this->copyFile($entry['fullpath'], $entry['path']);
{'fraction_non_alphanumeric': 0.14336324988190835, 'fraction_numerical': 0.0035427491733585263, 'mean_word_length': 2.4125705076551167, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7447281', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1236, 'n_words': 213}