MCPcopy Index your code
hub / github.com/diffgram/diffgram / check_export_billing

Function check_export_billing

shared/export/export_utils.py:83–150  ·  view source on GitHub ↗

(
    session,
    project,
    directory,
    member,
    log)

Source from the content-addressed store, hash-verified

81
82
83def check_export_billing(
84 session,
85 project,
86 directory,
87 member,
88 log):
89 """
90
91 """
92
93 logger.info('Checking Limits for Plan')
94 if settings.ALLOW_STRIPE_BILLING is False:
95 return log
96
97 checker = FeatureChecker(
98 session = session,
99 user = member.user,
100 project = project
101 )
102
103 max_allowed_instances = checker.get_limit_from_plan('MAX_INSTANCES_PER_EXPORT')
104 if max_allowed_instances is None:
105 return log
106
107 # Careful if it's a large project,
108 # And no other areas / no billing ID it can hang here ina funny way
109 # Put limit of 200 as a temp measure for this.
110
111 # Free case, could error or success
112 file_list = WorkingDirFileLink.file_list(
113 session = session,
114 working_dir_id = directory.id,
115 type = "image",
116 exclude_removed = True,
117 limit = 200
118 )
119
120 new_instance_count = 0
121
122 for file in file_list:
123 new_instance_count += Instance.list(
124 session = session,
125 file_id = file.id,
126 exclude_removed = True,
127 return_kind = "count")
128
129 logger.info(f"Checking limits for export with {new_instance_count} instances")
130
131 if max_allowed_instances:
132 if new_instance_count > max_allowed_instances:
133 message = 'Free Tier Limit Reached - Max Instances Allowed: {}. But Export has {} instances'.format(
134 max_allowed_instances,
135 new_instance_count
136 )
137 log['error']['over_free_plan_limit'] = True
138 log['error']['active_instances'] = new_instance_count
139 log['error']['free_tier_limit'] = message
140

Callers 1

create_new_exportFunction · 0.90

Calls 5

get_limit_from_planMethod · 0.95
FeatureCheckerClass · 0.90
file_listMethod · 0.80
listMethod · 0.45
newMethod · 0.45

Tested by

no test coverage detected