Skip to content

Commit

Permalink
New lock code, credit to Clark Van Oyen (https://github.com/countable) (
Browse files Browse the repository at this point in the history
#257)

* Create file lock per office, to limit lock contention
Put in one error check in the citizen_list endpoint
- Thanks to Clark Van Oyen (https://github.com/countable) for this code
* Add error check to POST as well as GET to /citizens/ endpoint
Update the version number
  • Loading branch information
ChrisDMac authored and gil0109 committed May 13, 2019
1 parent 1f43568 commit bec8eae
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions api/app/resources/theq/citizen/citizen_begin_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class CitizenBeginService(Resource):
@oidc.accept_token(require_token=True)
@api_call_with_retry
def post(self, id):
lock = FileLock("lock/begin_citizen.lock")
csr = CSR.find_by_username(g.oidc_token_info['username'])
lock = FileLock("lock/begin_citizen_{}.lock".format(csr.office_id))

with lock:
csr = CSR.find_by_username(g.oidc_token_info['username'])
citizen = Citizen.query.filter_by(citizen_id=id, office_id=csr.office_id).first()
pending_service_state = SRState.get_state_by_name("Active")

Expand Down
4 changes: 2 additions & 2 deletions api/app/resources/theq/citizen/citizen_generic_invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class CitizenGenericInvite(Resource):
@api_call_with_retry
def post(self):

lock = FileLock("lock/invite_citizen.lock")
csr = CSR.find_by_username(g.oidc_token_info['username'])
lock = FileLock("lock/invite_citizen_{}.lock".format(csr.office_id))

with lock:
csr = CSR.find_by_username(g.oidc_token_info['username'])

active_citizen_state = CitizenState.query.filter_by(cs_state_name='Active').first()
waiting_period_state = PeriodState.get_state_by_name("Waiting")
Expand Down
5 changes: 5 additions & 0 deletions api/app/resources/theq/citizen/citizen_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class CitizenList(Resource):
def get(self):
try:
csr = CSR.find_by_username(g.oidc_token_info['username'])
if not csr:
raise Exception('no user found with username: `{}`'.format(g.oidc_token_info['username']))
active_state = CitizenState.query.filter_by(cs_state_name="Active").first()
citizens = Citizen.query.filter_by(office_id=csr.office_id, cs_id=active_state.cs_id) \
.order_by(Citizen.priority) \
Expand All @@ -47,9 +49,12 @@ def get(self):
@oidc.accept_token(require_token=True)
@api_call_with_retry
def post(self):

json_data = request.get_json()

csr = CSR.find_by_username(g.oidc_token_info['username'])
if not csr:
raise Exception('no user found with username: `{}`'.format(g.oidc_token_info['username']))

try:
citizen = self.citizen_schema.load(json_data).data
Expand Down
4 changes: 2 additions & 2 deletions api/app/resources/theq/citizen/citizen_specific_invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class CitizenSpecificInvite(Resource):
@oidc.accept_token(require_token=True)
@api_call_with_retry
def post(self, id):
lock = FileLock("lock/invite_citizen.lock")
csr = CSR.find_by_username(g.oidc_token_info['username'])
lock = FileLock("lock/invite_citizen_{}.lock".format(csr.office_id))

with lock:
csr = CSR.find_by_username(g.oidc_token_info['username'])
citizen = db.session.query(Citizen).with_lockmode('update').filter_by(citizen_id=id).first()
active_service_state = SRState.get_state_by_name("Active")

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/layout/footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<a href="#" @click="keycloakLogin()" id="keycloak-login">Keycloak Login</a>
</div>
<div class="footer-anchor-item-last" style="display:inline-block; color: white; margin-right:15px;">
v1.0.25
v1.0.26
</div>
</div>
</div>
Expand Down

0 comments on commit bec8eae

Please sign in to comment.