Revision 84a3f701 snf-astakos-app/astakos/im/models.py
b/snf-astakos-app/astakos/im/models.py | ||
---|---|---|
70 | 70 |
SITENAME, SERVICES, MODERATION_ENABLED, RESOURCES_PRESENTATION_DATA) |
71 | 71 |
from astakos.im import settings as astakos_settings |
72 | 72 |
from astakos.im.endpoints.qh import ( |
73 |
register_users, register_quotas, qh_check_users, qh_get_quota_limits, |
|
73 | 74 |
register_services, register_resources, qh_add_quota, QuotaLimits, |
74 | 75 |
qh_query_serials, qh_ack_serials, |
75 | 76 |
QuotaValues, add_quota_values) |
... | ... | |
2010 | 2011 |
qh_ack_serials(list(serials_to_ack)) |
2011 | 2012 |
return len(memberships) |
2012 | 2013 |
|
2013 |
def pre_sync(): |
|
2014 |
def pre_sync_projects():
|
|
2014 | 2015 |
ACCEPTED = ProjectMembership.ACCEPTED |
2015 | 2016 |
PROJECT_DEACTIVATED = ProjectMembership.PROJECT_DEACTIVATED |
2016 | 2017 |
psfu = Project.objects.select_for_update() |
... | ... | |
2044 | 2045 |
membership.state = PROJECT_DEACTIVATED |
2045 | 2046 |
membership.save() |
2046 | 2047 |
|
2047 |
def do_sync(): |
|
2048 |
def do_sync_projects():
|
|
2048 | 2049 |
|
2049 | 2050 |
ACCEPTED = ProjectMembership.ACCEPTED |
2050 | 2051 |
objects = ProjectMembership.objects.select_for_update() |
... | ... | |
2085 | 2086 |
|
2086 | 2087 |
return serial |
2087 | 2088 |
|
2088 |
def post_sync(): |
|
2089 |
def post_sync_projects():
|
|
2089 | 2090 |
ACCEPTED = ProjectMembership.ACCEPTED |
2090 | 2091 |
PROJECT_DEACTIVATED = ProjectMembership.PROJECT_DEACTIVATED |
2091 | 2092 |
psfu = Project.objects.select_for_update() |
... | ... | |
2120 | 2121 |
|
2121 | 2122 |
transaction.commit() |
2122 | 2123 |
|
2123 |
def sync_projects():
|
|
2124 |
def _sync_projects(execute):
|
|
2124 | 2125 |
sync_finish_serials() |
2125 |
pre_sync() |
|
2126 |
serial = do_sync() |
|
2126 |
if not execute: |
|
2127 |
# Do some reporting and |
|
2128 |
return |
|
2129 |
|
|
2130 |
pre_sync_projects() |
|
2131 |
serial = do_sync_projects() |
|
2127 | 2132 |
sync_finish_serials([serial]) |
2128 |
post_sync() |
|
2133 |
post_sync_projects() |
|
2134 |
|
|
2135 |
def sync_projects(execute=True, retries=3, retry_wait=1.0): |
|
2136 |
return lock_sync(_sync_projects, |
|
2137 |
args=[execute], |
|
2138 |
retries=retries, |
|
2139 |
retry_wait=retry_wait) |
|
2140 |
|
|
2141 |
def _sync_users(users, execute): |
|
2142 |
sync_finish_serials() |
|
2143 |
|
|
2144 |
existing, nonexisting = qh_check_users(users) |
|
2145 |
resources = get_resource_names() |
|
2146 |
quotas = qh_get_quota_limits(existing, resources) |
|
2129 | 2147 |
|
2130 |
def trigger_sync(retries=3, retry_wait=1.0): |
|
2148 |
if execute: |
|
2149 |
r = register_users(nonexisting) |
|
2150 |
r = register_quotas(users) |
|
2151 |
|
|
2152 |
# TODO: some proper reporting |
|
2153 |
return (existing, nonexisting, quotas) |
|
2154 |
|
|
2155 |
def sync_users(users, execute=True, retries=3, retry_wait=1.0): |
|
2156 |
return lock_sync(_sync_users, |
|
2157 |
args=[users, execute], |
|
2158 |
retries=retries, |
|
2159 |
retry_wait=retry_wait) |
|
2160 |
|
|
2161 |
def sync_all_users(execute=True, retries=3, retry_wait=1.0): |
|
2162 |
users = AstakosUser.objects.all() |
|
2163 |
return sync_users(users, execute, retries=retries, retry_wait=retry_wait) |
|
2164 |
|
|
2165 |
def lock_sync(func, args=[], kwargs={}, retries=3, retry_wait=1.0): |
|
2131 | 2166 |
transaction.commit() |
2132 | 2167 |
|
2133 | 2168 |
cursor = connection.cursor() |
... | ... | |
2148 | 2183 |
return False |
2149 | 2184 |
sleep(retry_wait) |
2150 | 2185 |
|
2151 |
sync_projects() |
|
2152 |
return True |
|
2186 |
return func(*args, **kwargs) |
|
2153 | 2187 |
|
2154 | 2188 |
finally: |
2155 | 2189 |
if locked: |
Also available in: Unified diff