leadguru-jobs 0.623.0__py3-none-any.whl → 0.624.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.623.0
3
+ Version: 0.624.0
4
4
  Summary: LGT jobs builds
5
5
  Author-email: developer@leadguru.co
6
6
  Classifier: Development Status :: 5 - Production/Stable
@@ -1,4 +1,4 @@
1
- lgt_jobs/__init__.py,sha256=cZDNBmksAzKFe5frsPpucpYfC-3YlAhw2-cVzmMe8Oo,2335
1
+ lgt_jobs/__init__.py,sha256=efDX0VsSwC2we92quUu8E62MqC-4audo0Rv37Y6USnk,2144
2
2
  lgt_jobs/basejobs.py,sha256=LPEclvY6fIG17YMGy9pRK0Q58n62gkI5W1BTK6R2p-c,1234
3
3
  lgt_jobs/env.py,sha256=cRO03GGvstUjBsv3uYO-iakrOvAk_ZWUP_fnmf21iZQ,789
4
4
  lgt_jobs/main.py,sha256=cK_nkBtJHnUNDbba1WZotqPtI_6OWxiYQkAgco9OAmE,1539
@@ -21,7 +21,6 @@ lgt_jobs/jobs/mass_message.py,sha256=1mFcBlL2MhzLbj5yrd_NyJc7TXDWCcROAzGDnr0miMU
21
21
  lgt_jobs/jobs/send_code.py,sha256=dIlLPkG3GgGKIEqGiElyzrtdrnJNTL1Ak2V0xnE-WIQ,824
22
22
  lgt_jobs/jobs/send_slack_message.py,sha256=nNtuSsAIK5dzvP3B1G-BHNyk_LuZkHfsGmpXHHIqBb0,2329
23
23
  lgt_jobs/jobs/update_slack_profile.py,sha256=_ed0OhrVc1U-nE6dLckdmTmzZaxlK-y7h4S7SIpfEiA,3582
24
- lgt_jobs/jobs/user_balance_update.py,sha256=1262PdJhsQ2oly2vJFT6IQWLKoPnBXmMkGBgu1U7sSs,2441
25
24
  lgt_jobs/jobs/workspace_connect.py,sha256=y48LGLtH7KxB-XAja9JOW4VFq4rzJh8cSf6heNBLSx0,7067
26
25
  lgt_jobs/lgt_common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
26
  lgt_jobs/lgt_common/helpers.py,sha256=3T47_Abw7datSIxVqIHTCB-sh-rnahWrmrFG8sSY9ZE,178
@@ -50,7 +49,7 @@ lgt_jobs/lgt_data/models/message_request.py,sha256=3m_2uSqnLUHrQbhTEKednoC0KuxAC
50
49
  lgt_jobs/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
51
50
  lgt_jobs/services/web_client.py,sha256=oMyWJxwGeIe3f40fPT7xcisjDg3BhA3Ipf8dr1jVT-Y,1549
52
51
  lgt_jobs/templates/new_message.html,sha256=dZl8UmdAOOMq4nidvAgMFroSrTV7Pw0RWt2yLp_2idg,6989
53
- leadguru_jobs-0.623.0.dist-info/METADATA,sha256=HdXF8KzVG6SU0BV1YIgW-WhQzIRncF-ScnchOHXwLCo,1319
54
- leadguru_jobs-0.623.0.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
55
- leadguru_jobs-0.623.0.dist-info/top_level.txt,sha256=rIuw1DqwbnZyeoarBSC-bYeGOhv9mZBs7_afl9q4_JI,9
56
- leadguru_jobs-0.623.0.dist-info/RECORD,,
52
+ leadguru_jobs-0.624.0.dist-info/METADATA,sha256=B6K53VjOuKtsNrPPB_HoOoNF6KeAqFmt59lMiubn0No,1319
53
+ leadguru_jobs-0.624.0.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
54
+ leadguru_jobs-0.624.0.dist-info/top_level.txt,sha256=rIuw1DqwbnZyeoarBSC-bYeGOhv9mZBs7_afl9q4_JI,9
55
+ leadguru_jobs-0.624.0.dist-info/RECORD,,
lgt_jobs/__init__.py CHANGED
@@ -1,6 +1,5 @@
1
1
  name = "lgt_jobs"
2
2
 
3
- from .jobs.user_balance_update import UpdateUserBalanceJob, UpdateUserBalanceJobData
4
3
  from .jobs.send_slack_message import SendSlackMessageJob, SendSlackMessageJobData
5
4
  from .jobs.analytics import (TrackAnalyticsJob, TrackAnalyticsJobData)
6
5
  from .jobs.connect_sources import (ConnectSourceJobData, ConnectSourceJob)
@@ -22,7 +21,6 @@ jobs_map = {
22
21
  "LoadChatHistoryJob": LoadChatHistoryJob,
23
22
  "UpdateExternalUserProfileJob": UpdateExternalUserProfileJob,
24
23
  "SendSlackMessageJob": SendSlackMessageJob,
25
- "UpdateUserBalanceJob": UpdateUserBalanceJob,
26
24
  "SendMassMessageSlackChannelJob": SendMassMessageSlackChannelJob,
27
25
  "ConnectSourceJob": ConnectSourceJob,
28
26
  "LoadSlackPeopleJob": LoadSlackPeopleJob
@@ -37,7 +35,6 @@ __all__ = [
37
35
  UpdateExternalUserProfileJob,
38
36
  TrackAnalyticsJob,
39
37
  SendSlackMessageJob,
40
- UpdateUserBalanceJob,
41
38
  SendMassMessageSlackChannelJob,
42
39
  ConnectSourceJob,
43
40
  LoadSlackPeopleJob,
@@ -54,7 +51,6 @@ __all__ = [
54
51
  UpdateExternalUserProfileJobData,
55
52
  TrackAnalyticsJobData,
56
53
  SendSlackMessageJobData,
57
- UpdateUserBalanceJobData,
58
54
  SendMassMessageSlackChannelJobData,
59
55
  ConnectSourceJobData,
60
56
  LoadSlackPeopleJobData,
@@ -1,71 +0,0 @@
1
- import datetime
2
- from abc import ABC
3
- from typing import Optional
4
- from lgt_jobs.lgt_data.engine import UserCreditStatementDocument
5
- from lgt_jobs.lgt_data.enums import UserAccountState, UserAction
6
- from lgt_jobs.lgt_data.model import UserModel
7
- from lgt_jobs.lgt_data.mongo_repository import UserMongoRepository
8
- from lgt_jobs.lgt_data.helpers import to_object_id
9
- from pydantic import BaseModel
10
- from lgt_jobs.basejobs import BaseBackgroundJobData, BaseBackgroundJob
11
-
12
- """
13
- User balance handling
14
- """
15
-
16
-
17
- class UpdateUserBalanceJobData(BaseBackgroundJobData, BaseModel):
18
- user_id: Optional[str]
19
-
20
-
21
- class UpdateUserBalanceJob(BaseBackgroundJob, ABC):
22
- @property
23
- def job_data_type(self) -> type:
24
- return UpdateUserBalanceJobData
25
-
26
- @staticmethod
27
- def __update_processed(user: UserModel):
28
- pipeline = [
29
- {
30
- "$match": {
31
- "user_id": to_object_id(user.id),
32
- "balance": {"$lte": 0},
33
- "action": {"$nin": [UserAction.ADMIN_CREDITS_ADDED, UserAction.ADMIN_CREDITS_SET]}
34
- }
35
- },
36
- {
37
- '$group': {
38
- '_id': "$user_id",
39
- 'count': {'$sum': {"$multiply": [-1, "$balance"]}}
40
- }
41
- }
42
- ]
43
-
44
- results = list(UserCreditStatementDocument.objects.aggregate(*pipeline))
45
- if not results:
46
- return
47
-
48
- count = results[0]["count"]
49
- if count >= user.leads_limit:
50
- # suspend account
51
- if user.state != UserAccountState.Suspended.value:
52
- UserMongoRepository().set(user.id, leads_proceeded=count,
53
- credits_exceeded_at=datetime.datetime.now(datetime.UTC),
54
- state=UserAccountState.Suspended.value)
55
- return
56
-
57
- if user.state == UserAccountState.Suspended.value:
58
- # unsuspend account
59
- UserMongoRepository().set(user.id, leads_proceeded=count,
60
- credits_exceeded_at=None,
61
- state=UserAccountState.Operational.value)
62
- return
63
-
64
- UserMongoRepository().set(user.id, leads_proceeded=count)
65
-
66
- def exec(self, data: UpdateUserBalanceJobData):
67
- user = UserMongoRepository().get(data.user_id)
68
- if not user:
69
- return
70
-
71
- self.__update_processed(user=user)