6
6
import traceback
7
7
from uuid import UUID
8
8
9
- from .crawlmanager import CrawlManager
10
- from .db import init_db
11
- from .emailsender import EmailSender
12
-
13
- # from .utils import register_exit_handler
14
9
from .models import BgJobType
10
+ from .ops import init_ops
15
11
16
- from .basecrawls import BaseCrawlOps
17
- from .invites import InviteOps
18
- from .users import init_user_manager
19
- from .orgs import OrgOps
20
- from .colls import CollectionOps
21
- from .crawlconfigs import CrawlConfigOps
22
- from .crawls import CrawlOps
23
- from .profiles import ProfileOps
24
- from .storages import StorageOps
25
- from .webhooks import EventWebhookOps
26
- from .background_jobs import BackgroundJobOps
27
- from .pages import PageOps
28
12
29
13
job_type = os .environ .get ("BG_JOB_TYPE" )
30
14
oid = os .environ .get ("OID" )
33
17
# ============================================================================
34
18
# pylint: disable=too-many-function-args, duplicate-code, too-many-locals
35
19
async def main ():
36
- """main init"""
37
- email = EmailSender ()
38
- crawl_manager = None
39
-
40
- dbclient , mdb = init_db ()
41
-
42
- invite_ops = InviteOps (mdb , email )
43
-
44
- user_manager = init_user_manager (mdb , email , invite_ops )
45
-
46
- org_ops = OrgOps (mdb , invite_ops , user_manager )
47
-
48
- event_webhook_ops = EventWebhookOps (mdb , org_ops )
20
+ """run background job with access to ops classes"""
49
21
50
22
# pylint: disable=import-outside-toplevel
51
23
if not os .environ .get ("KUBERNETES_SERVICE_HOST" ):
@@ -55,66 +27,7 @@ async def main():
55
27
)
56
28
sys .exit (1 )
57
29
58
- crawl_manager = CrawlManager ()
59
-
60
- storage_ops = StorageOps (org_ops , crawl_manager )
61
-
62
- background_job_ops = BackgroundJobOps (
63
- mdb , email , user_manager , org_ops , crawl_manager , storage_ops
64
- )
65
-
66
- profile_ops = ProfileOps (
67
- mdb , org_ops , crawl_manager , storage_ops , background_job_ops
68
- )
69
-
70
- crawl_config_ops = CrawlConfigOps (
71
- dbclient ,
72
- mdb ,
73
- user_manager ,
74
- org_ops ,
75
- crawl_manager ,
76
- profile_ops ,
77
- )
78
-
79
- coll_ops = CollectionOps (mdb , crawl_manager , org_ops , event_webhook_ops )
80
-
81
- base_crawl_ops = BaseCrawlOps (
82
- mdb ,
83
- user_manager ,
84
- org_ops ,
85
- crawl_config_ops ,
86
- coll_ops ,
87
- storage_ops ,
88
- event_webhook_ops ,
89
- background_job_ops ,
90
- )
91
-
92
- crawl_ops = CrawlOps (
93
- crawl_manager ,
94
- mdb ,
95
- user_manager ,
96
- org_ops ,
97
- crawl_config_ops ,
98
- coll_ops ,
99
- storage_ops ,
100
- event_webhook_ops ,
101
- background_job_ops ,
102
- )
103
-
104
- page_ops = PageOps (mdb , crawl_ops , org_ops , storage_ops )
105
-
106
- base_crawl_ops .set_page_ops (page_ops )
107
- crawl_ops .set_page_ops (page_ops )
108
-
109
- background_job_ops .set_ops (crawl_ops , profile_ops )
110
-
111
- org_ops .set_ops (base_crawl_ops , profile_ops , coll_ops , background_job_ops )
112
-
113
- user_manager .set_ops (org_ops , crawl_config_ops , base_crawl_ops )
114
-
115
- background_job_ops .set_ops (base_crawl_ops , profile_ops )
116
-
117
- crawl_config_ops .set_coll_ops (coll_ops )
30
+ (org_ops , _ , _ , _ , _ , _ , _ , _ , _ , _ , user_manager ) = init_ops ()
118
31
119
32
# Run job
120
33
if job_type == BgJobType .DELETE_ORG :
0 commit comments