<commit_before><?php
namespace mle86\WQ\WorkServerAdapter;

use mle86\WQ\Job\Job;
use mle86\WQ\Job\QueueEntry;

/**
 * This Work Server Adapter
 * uses an array for "persistence".
 *
 * @internal  This is here for testing purposes.
 */
class MemoryWorkServer
	implements WorkServerAdapter
{

	const RESERVE_SECONDS = 60;

	/**
	 * @var array  <pre>[ workQueueName => [
	 *       idx  => [ activeTimestamp,  jobData  ],
	 *       idx2 => [ activeTimestamp2, job2Data ],
	 *       ...
	 *     ],
	 *     ...
	 *   ] </pre>
	 */
	protected $storage = [ ];

	protected static $index = 0;


	public function getNextQueueEntry ($workQueues, int $timeout = self::DEFAULT_TIMEOUT) : ?QueueEntry {
		$all_empty = true;
		foreach ((array)$workQueues as $workQueue) {
			if (!empty($this->storage[$workQueue])) {
				$all_empty = false;
				break;
			}
		}
		if ($all_empty) {
			if ($timeout > 0) {
				sleep($timeout);
			}
			return null;
		}

		foreach ((array)$workQueues as $workQueue) {
			foreach ($this->storage[$workQueue] as $idx => $jobInfo) {
				$activeTimestamp = $jobInfo[0];
				$jobData         = $jobInfo[1];

				if ($activeTimestamp <= time()) {
					// reserve and return:
					$activeTimestamp += self::RESERVE_SECONDS;
					$this->storage[$workQueue][$idx][0] = $activeTimestamp;

					return QueueEntry::fromSerializedJob($jobData, $workQueue, $idx, $idx);
				} else {
					// this job is delayed, skip
				}
			}
		}

		if ($timeout > 0) {
			sleep(1);
			return $this->getNextQueueEntry($workQueues, $timeout - 1);
		}

		return null;
	}<commit_msg>MemoryWS: no error on unknown wq<commit_after><?php
namespace mle86\WQ\WorkServerAdapter;

use mle86\WQ\Job\Job;
use mle86\WQ\Job\QueueEntry;

/**
 * This Work Server Adapter
 * uses an array for "persistence".
 *
 * @internal  This is here for testing purposes.
 */
class MemoryWorkServer
	implements WorkServerAdapter
{

	const RESERVE_SECONDS = 60;

	/**
	 * @var array  <pre>[ workQueueName => [
	 *       idx  => [ activeTimestamp,  jobData  ],
	 *       idx2 => [ activeTimestamp2, job2Data ],
	 *       ...
	 *     ],
	 *     ...
	 *   ] </pre>
	 */
	protected $storage = [ ];

	protected static $index = 0;


	public function getNextQueueEntry ($workQueues, int $timeout = self::DEFAULT_TIMEOUT) : ?QueueEntry {
		$all_empty = true;
		foreach ((array)$workQueues as $workQueue) {
			if (!empty($this->storage[$workQueue])) {
				$all_empty = false;
				break;
			}
		}
		if ($all_empty) {
			if ($timeout > 0) {
				sleep($timeout);
			}
			return null;
		}

		foreach ((array)$workQueues as $workQueue) {
			foreach (($this->storage[$workQueue] ?? []) as $idx => $jobInfo) {
				$activeTimestamp = $jobInfo[0];
				$jobData         = $jobInfo[1];

				if ($activeTimestamp <= time()) {
					// reserve and return:
					$activeTimestamp += self::RESERVE_SECONDS;
					$this->storage[$workQueue][$idx][0] = $activeTimestamp;

					return QueueEntry::fromSerializedJob($jobData, $workQueue, $idx, $idx);
				} else {
					// this job is delayed, skip
				}
			}
		}

		if ($timeout > 0) {
			sleep(1);
			return $this->getNextQueueEntry($workQueues, $timeout - 1);
		}

		return null;
	}
{'fraction_non_alphanumeric': 0.15606204495093384, 'fraction_numerical': 0.01202912314023425, 'mean_word_length': 2.910891089108911, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, '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': '5822172', 'n_tokens_mistral': 1261, 'n_tokens_neox': 1065, 'n_words': 241}