APScheduler не выполняется должным образом

#python #apscheduler

#python #apscheduler

Вопрос:

У меня есть пара пользовательских модулей, которые вызываются из clock.py бегущий apscheduler :

Проблема, вызванная APScheduler

apscheduler продолжает вставлять одну и ту же дату снова и снова с запланированными интервалами, когда сначала он должен проверять ленту Twitter, а затем, если отличается от вставки Google sheet, ничего не делать.

Модули

  1. clock.py:
    1. создает экземпляры BlockingScheduler()
    2. задание расписания
    3. .start() задание
  2. модуль tweet_bss.py:
    1. проверяет канал твитов:
      1. сравнивает текущее значение фида с сохраненным значением в таблицах Google.
    2. If значения разные:
      1. Добавляет новое значение в таблицу Google
      2. обновляет локальный файл состояния
  3. модуль dev_smtplib.py:
    1. проверяет файл состояния
      1. если статус True , отправляет обновление по электронной почте

В настоящее время проблема заключается в clock.py и модуль а

clock.py

 sched = BlockingScheduler()
sched.add_job(tweet_bss.main, 'interval', seconds = 120)
sched.print_jobs()
sched.start()
  

Модуль tweet_bss.main()

 def main():
    """
    This script will import the sheets module, open a connection to twitter
    pass account name and numb of tweets open a connection with sheets,
    if last row 'text' from 'sheets' != 'tweet text' and 'is not None'
    then it will enter the exchange into the spread sheet
    """
    last_row = sheets.row_count()
    last_entry = sheets.get_text(last_row)
    last_entry = str(last_entry)
    for tweet in tweets('tweet_account', 1):
        if last_entry != bss_extract(tweet.text) is not None:
            sheets.bss_insert([str(tweet.created_at), tweet.lang,
                               tweet.source_url, float(bss_extract(tweet.text))])
            pickler([str(tweet.created_at), float(bss_extract(tweet.text))])
            sc.bss_update(True)
            print(f'from tweet_bss.py for {TODAY} @ {TIME}')
            print(f'if {last_entry} != {bss_extract(tweet.text)} is not None')
            print(f'a. Twitter data inserted on {tweet.created_at} to sheets')
            print('b. pickler() function updated the pickle file with date and exchange rate to be used for email')
            print('c. The status.yaml was updated to True, letting the SMTP script know "update" can be emailed')
            print('~' * 45)
        else:
            print(f'from tweet_bss.py for {TODAY} @ {TIME}')
            print(f'No update needed:')
            print(f'tSheets last entry {last_entry} == {bss_extract(tweet.text)} (current tweet exchange) and is not None')
            print('tt* The email pickle was not updated with exchange rate and date')
            print('tt* The status was not updated to True')
            print('~' * 45)
  

То, что я ожидал, произойдет:

  • Чтобы вызвать apscheduler tweet_bss.py проверяйте ленту Twitter каждый раз при выполнении запланированного задания, не загружая ничего в память, и обновляйте таблицу Google, если tweet_feed != google.sheets

Что происходит:

  • apscheduler проверяет канал Twitter только один раз, и если tweet_feed != google.sheets обновляет Google.лист, как и ожидалось, НО

Проблема

  • apscheduler продолжает вставлять одну и ту же дату снова и снова с запланированными интервалами, когда он должен каждый раз проверять ленту Twitter.
 """
print statements I wrote for particular conditions in Module A
"""

Pending jobs:
    main (trigger: interval[0:02:00], pending)

from tweet_bss.py for 2019-04-15 @ 15:12:09
if 5009.63 != 5015.26 is not None
Twitter data inserted on 2019-04-15 19:07:19 to sheets
pickler() function updated the pickle file with date and exchange rate to be used for email
the status.yaml was updated to True, letting the SMTP script know it can be email
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from tweet_bss.py for 2019-04-15 @ 15:12:09
if 5009.63 != 5015.26 is not None
Twitter data inserted on 2019-04-15 19:07:19 to sheets
pickler() function updated the pickle file with date and exchange rate to be used for email
the status.yaml was updated to True, letting the SMTP script know it can be email
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from tweet_bss.py for 2019-04-15 @ 15:12:09
if 5009.63 != 5015.26 is not None
Twitter data inserted on 2019-04-15 19:07:19 to sheets
pickler() function updated the pickle file with date and exchange rate to be used for email
the status.yaml was updated to True, letting the SMTP script know it can be email
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from tweet_bss.py for 2019-04-15 @ 15:12:09
if 5009.63 != 5015.26 is not None
Twitter data inserted on 2019-04-15 19:07:19 to sheets
pickler() function updated the pickle file with date and exchange rate to be used for email
the status.yaml was updated to True, letting the SMTP script know it can be email
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  

Как мне заставить apscheduler выполняться tweet_bss.py по назначению?

Спасибо!

Комментарии:

1. Как вы думаете, почему проблема связана с APScheduler? Он не содержит никаких таблиц Google или кода Twitter. Откуда TODAY и TIME откуда?

2. Привет, Алекс, я не могу опубликовать другие скрипты и модули из-за размера. И я думаю, что вы правы, вчера поздно вечером мне пришло в голову, что проблема связана с областью действия в основной функции, опубликованной выше. Я внес изменения, но не смог их протестировать, питание продолжает отключаться. Опять же, это часть микросервиса, и это путь к большему. После устранения этой проблемы могут возникнуть другие проблемы.