def __init__(self, job_queue: JobQueue):
self.job_queue = job_queue
self.jobs = []
python类JobQueue()的实例源码
def __init__(self, job_queue: JobQueue):
self.job_queue = job_queue
def do_login(bot: Bot, chat_id: str, sender: str, token: str, job_queue: JobQueue):
from bot_app.model import Conversation
global data
try:
# Notify this is going to take some time
# In groups
if data.change_account_queries[sender] != sender:
bot.sendChatAction(chat_id=chat_id, action=ChatAction.TYPING)
# In private chat
bot.sendChatAction(chat_id=chat_id, action=ChatAction.TYPING)
# Create Tinder session
session = Session(token)
if session.do_connect():
message = "Switching to %s's account." % session.get_profile_name()
messages.send_custom_message(bot=bot, message=message, chat_id=data.change_account_queries[sender])
if sender != data.change_account_queries[sender]:
# group_name = bot.getChat(chat_id=data.change_account_queries[sender]).title
bot.sendMessage(chat_id=sender,
text=message,
reply_markup=keyboards.switch_group_keyboard())
# Create conversation
conversation = Conversation(data.change_account_queries[sender], session, sender)
data.conversations[data.change_account_queries[sender]] = conversation
del data.change_account_queries[sender]
# Launch get matches background job
cache_time = int(conversation.settings.get_setting("matches_cache_time"))
job = Job(job_refresh_matches, cache_time + 1, repeat=True, context=conversation)
job_queue.put(job, next_t=0.0)
else:
messages.send_error(bot=bot, chat_id=chat_id, name="auth_failed")
except BaseException:
messages.send_error(bot=bot, chat_id=chat_id, name="auth_failed")
def init(*, bot: Bot, job_queue: JobQueue, callback: callable):
_load_all()
_configure_logging(bot)
for chat in auto_spins:
job = job_queue.run_daily(callback, str_to_time(auto_spins[chat]), context=chat)
auto_spin_jobs.update({chat: job})
def __init__(self,
token=None,
base_url=None,
workers=4,
bot=None,
user_sig_handler=None,
request_kwargs=None):
if (token is None) and (bot is None):
raise ValueError('`token` or `bot` must be passed')
if (token is not None) and (bot is not None):
raise ValueError('`token` and `bot` are mutually exclusive')
if bot is not None:
self.bot = bot
else:
# we need a connection pool the size of:
# * for each of the workers
# * 1 for Dispatcher
# * 1 for polling Updater (even if webhook is used, we can spare a connection)
# * 1 for JobQueue
# * 1 for main thread
if request_kwargs is None:
request_kwargs = {}
if 'con_pool_size' not in request_kwargs:
request_kwargs['con_pool_size'] = workers + 4
self._request = Request(**request_kwargs)
self.bot = Bot(token, base_url, request=self._request)
self.user_sig_handler = user_sig_handler
self.update_queue = Queue()
self.job_queue = JobQueue(self.bot)
self.__exception_event = Event()
self.dispatcher = Dispatcher(
self.bot,
self.update_queue,
job_queue=self.job_queue,
workers=workers,
exception_event=self.__exception_event)
self.last_update_id = 0
self.logger = logging.getLogger(__name__)
self.running = False
self.is_idle = False
self.httpd = None
self.__lock = Lock()
self.__threads = []
""":type: list[Thread]"""
def __init__(self,
token=None,
base_url=None,
workers=4,
bot=None,
user_sig_handler=None,
request_kwargs=None):
if (token is None) and (bot is None):
raise ValueError('`token` or `bot` must be passed')
if (token is not None) and (bot is not None):
raise ValueError('`token` and `bot` are mutually exclusive')
self.logger = logging.getLogger(__name__)
con_pool_size = workers + 4
if bot is not None:
self.bot = bot
if bot.request.con_pool_size < con_pool_size:
self.logger.warning(
'Connection pool of Request object is smaller than optimal value (%s)',
con_pool_size)
else:
# we need a connection pool the size of:
# * for each of the workers
# * 1 for Dispatcher
# * 1 for polling Updater (even if webhook is used, we can spare a connection)
# * 1 for JobQueue
# * 1 for main thread
if request_kwargs is None:
request_kwargs = {}
if 'con_pool_size' not in request_kwargs:
request_kwargs['con_pool_size'] = con_pool_size
self._request = Request(**request_kwargs)
self.bot = Bot(token, base_url, request=self._request)
self.user_sig_handler = user_sig_handler
self.update_queue = Queue()
self.job_queue = JobQueue(self.bot)
self.__exception_event = Event()
self.dispatcher = Dispatcher(
self.bot,
self.update_queue,
job_queue=self.job_queue,
workers=workers,
exception_event=self.__exception_event)
self.last_update_id = 0
self.running = False
self.is_idle = False
self.httpd = None
self.__lock = Lock()
self.__threads = []