leadguru-jobs 0.256.0__py3-none-any.whl → 0.257.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: leadguru-jobs
3
- Version: 0.256.0
3
+ Version: 0.257.0
4
4
  Summary: LGT jobs builds
5
5
  Author-email: developer@leadguru.co
6
6
  Classifier: Development Status :: 5 - Production/Stable
@@ -8,7 +8,7 @@ lgt_jobs/smtp.py,sha256=W9OIkckBORAWEsNgIG3nVKs6OTU6esZNnq09WDsj8Lc,1352
8
8
  lgt_jobs/jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  lgt_jobs/jobs/analytics.py,sha256=bNQpYBPz6CMN0i-wXDzQKcc1L8UYUvyiVGJbUeGdf9Q,1307
10
10
  lgt_jobs/jobs/archive_leads.py,sha256=wZ4LwbuC9G7NB16AO15YiMemEV40LoJVjd8VRqaFv9o,831
11
- lgt_jobs/jobs/bot_stats_update.py,sha256=T6R1kbeO9Qnm8z8daDdET5jB0y8qk1dRXrMzDdlpk4k,2946
11
+ lgt_jobs/jobs/bot_stats_update.py,sha256=o4aSm7byBpnaIRMiVeSijif99nyJXjzWHHldvEK-lCQ,3466
12
12
  lgt_jobs/jobs/chat_history.py,sha256=z9_WfmCyDc-r_qK-Eze4tnEG3ek-HUxyHa8ywSSraA4,5620
13
13
  lgt_jobs/jobs/clear_user_analytics.py,sha256=sP90jhOcZqs67hJV-lJyFJH9Iciqai8IsbNs5fSc90U,2478
14
14
  lgt_jobs/jobs/conversation_replied.py,sha256=pMkalznkVt_j20VfXzZcaGIMXxkIknxDlHKvu4_yrrs,2584
@@ -25,7 +25,7 @@ lgt_jobs/jobs/workspace_connect.py,sha256=-EL6YrUhAOAR3dv1HZ12D9xvxL1JHP5208eh6s
25
25
  lgt_jobs/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
26
  lgt_jobs/services/web_client.py,sha256=SZogxjM0jyACRqBOP5EJvtqwe44og8B5B6TMWLpYmKM,1878
27
27
  lgt_jobs/templates/new_message_mail_template.html,sha256=82XdDPtmkJVUWUcZtgd8bv_9-viAG2WWOnf3AhR6PeY,3635
28
- leadguru_jobs-0.256.0.dist-info/METADATA,sha256=byypG0MpDIXu1FGtAD_NMieBKxhVIZAcYn5BewC0D0Y,1181
29
- leadguru_jobs-0.256.0.dist-info/WHEEL,sha256=5sUXSg9e4bi7lTLOHcm6QEYwO5TIF1TNbTSVFVjcJcc,92
30
- leadguru_jobs-0.256.0.dist-info/top_level.txt,sha256=rIuw1DqwbnZyeoarBSC-bYeGOhv9mZBs7_afl9q4_JI,9
31
- leadguru_jobs-0.256.0.dist-info/RECORD,,
28
+ leadguru_jobs-0.257.0.dist-info/METADATA,sha256=Ye1KHnKeyKqy7Czjr0HSgWaeB40_j1gKG8CdVlZkfQ0,1181
29
+ leadguru_jobs-0.257.0.dist-info/WHEEL,sha256=5sUXSg9e4bi7lTLOHcm6QEYwO5TIF1TNbTSVFVjcJcc,92
30
+ leadguru_jobs-0.257.0.dist-info/top_level.txt,sha256=rIuw1DqwbnZyeoarBSC-bYeGOhv9mZBs7_afl9q4_JI,9
31
+ leadguru_jobs-0.257.0.dist-info/RECORD,,
@@ -1,6 +1,7 @@
1
1
  from abc import ABC
2
2
  from typing import Optional
3
3
  from lgt.common.python.slack_client.web_client import SlackWebClient
4
+ from lgt_data.model import DedicatedBotModel
4
5
  from lgt_data.mongo_repository import BotMongoRepository, DedicatedBotRepository
5
6
  from pydantic import BaseModel
6
7
  from lgt_data.analytics import get_bots_aggregated_analytics
@@ -31,21 +32,23 @@ class BotStatsUpdateJob(BaseBackgroundJob, ABC):
31
32
  bots_rep = BotMongoRepository()
32
33
  bot = bots_rep.get_by_id(data.bot_name)
33
34
 
34
- if not bot.invalid_creds:
35
- return
35
+ client = SlackWebClient(bot.token, bot.cookies)
36
+ if bot.invalid_creds:
37
+ test_auth_response = client.test_auth()
38
+ if ((test_auth_response.status_code == 200) and
39
+ (test_auth_response.json().get("error") != SlackErrors.INVALID_AUTH)):
40
+ BotStatsUpdateJob.__updated_invalid_creds_flag(bot, False)
36
41
 
37
42
  received_messages, filtered_messages = get_bots_aggregated_analytics(bot_ids=[bot.id])
38
- client = SlackWebClient(bot.token, bot.cookies)
39
43
  if not bot.token or not bot.cookies:
40
44
  log.warning(f"[BotStatsUpdateJob]: Bot {bot.id} has no credentials.")
41
- bot.invalid_creds = True
42
- bots_rep.add_or_update(bot)
45
+ if not bot.invalid_creds:
46
+ BotStatsUpdateJob.__updated_invalid_creds_flag(bot, True)
43
47
  return
44
48
  channels_response = client.channels_list()
45
49
  if not channels_response['ok']:
46
50
  if channels_response.get("error") == SlackErrors.INVALID_AUTH:
47
- bot.invalid_creds = True
48
- bots_rep.add_or_update(bot)
51
+ BotStatsUpdateJob.__updated_invalid_creds_flag(bot, True)
49
52
  else:
50
53
  log.warning(f"[BotStatsUpdateJob]: Error during update bot {bot.id} stats. Error: {channels_response}")
51
54
  return
@@ -75,3 +78,8 @@ class BotStatsUpdateJob(BaseBackgroundJob, ABC):
75
78
  # save only last 50 messages
76
79
  bot.recent_messages = bot.recent_messages[-50:]
77
80
  bots_rep.add_or_update(bot)
81
+
82
+ @staticmethod
83
+ def __updated_invalid_creds_flag(bot: DedicatedBotModel, invalid_creds: bool):
84
+ bot.invalid_creds = invalid_creds
85
+ DedicatedBotRepository().add_or_update(bot)