示例#1
0
	def schedule_new_submission(self):
		# Attempt to schedule a new submission
		# Check that one has not been completed or in the process of, before submitting

		# Filters for Things which have been submitted successfully or
		# that are in the process of (ie attempts counter has not maxed out)
		recent_submissions = list(db_Thing.select(db_Thing).where((db_Thing.posted_name.is_null(False)) | (db_Thing.text_generation_attempts < 3 & db_Thing.reddit_post_attempts < 1)).
					where(fn.Lower(db_Thing.subreddit) == self._subreddit.lower()).
					where(db_Thing.source_name == 't3_new_submission').
					where((datetime.timestamp(datetime.utcnow()) - db_Thing.created_utc) < self._new_submission_frequency.total_seconds()))

		if recent_submissions:
			# There was a submission recently so we cannot proceed.
			return

		logging.info(f"Scheduling a new submission on {self._subreddit}")

		new_submission_thing = {}

		new_submission_thing['source_name'] = 't3_new_submission'
		new_submission_thing['subreddit'] = self._subreddit

		text_generation_parameters = self._default_text_generation_parameters.copy()
		text_generation_parameters['prompt'] = self._get_random_new_submission_tag()
		text_generation_parameters['max_length'] = 1000

		new_submission_thing['text_generation_parameters'] = text_generation_parameters

		return db_Thing.create(**new_submission_thing)
示例#2
0
	def pending_new_submission_jobs(self):
		# A list of pending Submission Things from the database that have had text generated,
		# but not a reddit post attempt
		return list(db_Thing.select(db_Thing).
					where(db_Thing.source_name == 't3_new_submission').
					where(db_Thing.reddit_post_attempts < 1).
					where(db_Thing.generated_text.is_null(False)).
					where(db_Thing.posted_name.is_null()))
示例#3
0
    def top_pending_jobs(self):
        """
		Get a list of text that need text to be generated, by treating
		each database Thing record as a 'job'.
		Three attempts at text generation are allowed.

		"""

        query = db_Thing.select(db_Thing).\
           where(db_Thing.text_generation_parameters.is_null(False)).\
           where(db_Thing.generated_text.is_null()).\
           where(db_Thing.text_generation_attempts < 3).\
           order_by(db_Thing.created_utc)
        return list(query)