<commit_before><?php
/**
 * @copyright 2015 dSpace Labs LLC
 * @license MIT
 */

namespace Dspacelabs\Component\Queue;

/**
 * Stores files on local disk for use as a queue
 */
class FileQueue extends Queue
{
    /**
     * @var string
     */
    protected $path;

    /**
     * @param string $name
     *   Name of the queue
     * @param string $path
     *   The path to where files are stored
     */
    public function __construct($name, $path)
    {
        $this->name = $name;
        $this->path = realpath($path);
    }

    /**
     * {@inheritDoc}
     */
    public function publish(MessageInterface $message)
    {
        $fname = time();
        $path  = sprintf('%s/%s.%s.message', $this->path, $this->name, $fname);
        $file  = new \splFileObject($path, 'w');
        $file->fwrite(serialize($message));
    }

    /**
     * {@inheritDoc}
     */
    public function receive()
    {
        // fetch from disk
        $paths = glob(sprintf('%s/%s.*.message', $this->path, $this->name));
        foreach ($paths as $path) {
            if (0 === filesize($path)) {
                // Nothing in this file, skip and move on
                unlink($path);
                continue;
            }
            $message = unserialize(file_get_contents($path));
            $message->addAttribute('path', $path);
            return $message;
        }
    }

    /**
     * {@inheirDoc}
     */
    public function delete(MessageInterface $message)
    {<commit_msg>publishing massive amounts messages to the file queue just puts it in one file =(<commit_after><?php
/**
 * @copyright 2015 dSpace Labs LLC
 * @license MIT
 */

namespace Dspacelabs\Component\Queue;

/**
 * Stores files on local disk for use as a queue
 */
class FileQueue extends Queue
{
    /**
     * @var string
     */
    protected $path;

    /**
     * @param string $name
     *   Name of the queue
     * @param string $path
     *   The path to where files are stored
     */
    public function __construct($name, $path)
    {
        $this->name = $name;
        $this->path = realpath($path);
    }

    /**
     * {@inheritDoc}
     */
    public function publish(MessageInterface $message)
    {
        $content = serialize($message);
        $fname   = hash('sha256', $content.microtime());
        $path    = sprintf('%s/%s.%s.message', $this->path, $this->name, $fname);
        $file    = new \splFileObject($path, 'w');
        $file->fwrite($content);
    }

    /**
     * {@inheritDoc}
     */
    public function receive()
    {
        // fetch from disk
        $paths = glob(sprintf('%s/%s.*.message', $this->path, $this->name));
        foreach ($paths as $path) {
            if (0 === filesize($path)) {
                // Nothing in this file, skip and move on
                unlink($path);
                continue;
            }
            $message = unserialize(file_get_contents($path));
            $message->addAttribute('path', $path);
            return $message;
        }
    }

    /**
     * {@inheirDoc}
     */
    public function delete(MessageInterface $message)
    {
{'fraction_non_alphanumeric': 0.14782608695652175, 'fraction_numerical': 0.004186795491143317, 'mean_word_length': 1.8495412844036698, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '575690', 'n_tokens_mistral': 938, 'n_tokens_neox': 911, 'n_words': 235}