<commit_before><?php

namespace eland;

use eland\cache;
use Predis\Client as Redis;

class schedule
{
	private $cache;
	private $redis;

	private $tasks;
	private $time;
	private $next;
	private $interval;
	private $id;

	public function __construct(cache $cache, Redis $redis)
	{
		$this->cache = $cache;
		$this->redis = $redis;

		$this->tasks = $this->cache->get('tasks');
	}

	public function set_time(int $time = 0)
	{
		$this->time = $time ? $time : time();
		return $this;
	}

	public function get_time()
	{
		if (!isset($this->time))
		{
			$this->time = time();
		}

		return $this->time();
	}

	public function set_id(string $id)
	{
		$this->id = $id;
		return $this;
	}

	public function get_id()
	{
		return $this->id;
	}

	public function set_interval(int $interval = 0)
	{
		$this->interval = $interval;
		return $this;
	}

	public function get_interval()
	{
		return $this->interval;
	}

	public function exists()
	{
		return isset($this->tasks[$this->id]) ? true : false;
	}

	public function should_run()
	{
		if ($this->redis->get('block_task'))
		{
			return false;
		}

		if (!$this->exists())
		{
			$this->redis->set('block_task', '1');
			$this->redis->expire('block_task', 3);
			$this->update();
			return false;
		}

		$last = strtotime($this->tasks[$this->id] . ' UTC');

		$this->next = $last + $this->interval;

		if ($this->next < $this->time)
		{
			$this->redis->set('block_task', '1');
			$this->redis->expire('block_task', 3);
			$this->update();
			return true;
		}

		return false;
	}

	private function update()
	{
		$next = ((($this->time - $this->next) > 43200) || ($this->interval < 43201)) ? $this->time : $this->next;<commit_msg>test block any task interval under 12 min<commit_after><?php

namespace eland;

use eland\cache;
use Predis\Client as Redis;

class schedule
{
	private $cache;
	private $redis;

	private $tasks;
	private $time;
	private $next;
	private $interval;
	private $id;

	public function __construct(cache $cache, Redis $redis)
	{
		$this->cache = $cache;
		$this->redis = $redis;

		$this->tasks = $this->cache->get('tasks');
	}

	public function set_time(int $time = 0)
	{
		$this->time = $time ? $time : time();
		return $this;
	}

	public function get_time()
	{
		if (!isset($this->time))
		{
			$this->time = time();
		}

		return $this->time();
	}

	public function set_id(string $id)
	{
		$this->id = $id;
		return $this;
	}

	public function get_id()
	{
		return $this->id;
	}

	public function set_interval(int $interval = 0)
	{
		$this->interval = $interval;
		return $this;
	}

	public function get_interval()
	{
		return $this->interval;
	}

	public function exists()
	{
		return isset($this->tasks[$this->id]) ? true : false;
	}

	public function should_run()
	{
		if ($this->redis->get('block_task'))
		{
			return false;
		}

		if (!$this->exists())
		{
			$this->redis->set('block_task', '1');
			$this->redis->expire('block_task', 3);
			$this->update();
			return false;
		}

		$last = strtotime($this->tasks[$this->id] . ' UTC');

		// test 12 min
		if (($this->time - $last) < 720)
		{
			return false;
		}

		$this->next = $last + $this->interval;

		if ($this->next < $this->time)
		{
			$this->redis->set('block_task', '1');
			$this->redis->expire('block_task', 3);
			$this->update();
			return true;
		}

		return false;
	}

	private function update()
	{
		$next = ((($this->time - $this->next) > 43200) || ($this->interval < 43201)) ? $this->time : $this->next;
{'fraction_non_alphanumeric': 0.1943800695249131, 'fraction_numerical': 0.011297798377752027, 'mean_word_length': 3.359848484848485, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 84, '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': '3701666', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1304, 'n_words': 287}