mumuki-domain 9.3.0 → 9.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/with_pg_lock.rb +19 -0
- data/app/models/concerns/with_reminders.rb +3 -12
- data/app/models/exam_authorization_request.rb +1 -1
- data/app/models/exam_registration.rb +13 -0
- data/db/migrate/20210512200453_add_processed_flag_to_exam_registration.rb +5 -0
- data/lib/mumuki/domain/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddd0081f4ed25d268fe17c327be9b5b343a21b2491eb737db4ee837fb16eead8
|
4
|
+
data.tar.gz: 7e34398bd300598d749d628af5ae31a49985ff62f8dda2ce2598169197cacc2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87e8fbb20f42949df631f2696c1d10a0c40744b7f84a1c7b705e525a8f2120a1e1ce5a58231a9bb9c2faa4987bd031eba01d3eb01a3e407f7202c4469eaeda72
|
7
|
+
data.tar.gz: 9196ae6c744c474853ffb027cf86f015546539ef994f83c62f27199123e54dbda3372fbd141a22f86c349270a0d14b1e6cdf3fdda47f3476bc6cd594ceb6e742
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module WithPgLock
|
2
|
+
##
|
3
|
+
# Lock PG table, reload model and execute callback if
|
4
|
+
# criterion is met
|
5
|
+
#
|
6
|
+
def with_pg_lock(callback, criterion = proc { true })
|
7
|
+
# Some notes:
|
8
|
+
#
|
9
|
+
# * nowait is a postgre specific option and may not work with other databases
|
10
|
+
# * nowait will raise an exception if the lock can not be acquired
|
11
|
+
# * we are using a double check lock pattern to reduce lock acquisition
|
12
|
+
with_lock('for update nowait') do
|
13
|
+
reload
|
14
|
+
callback.call if criterion.call
|
15
|
+
end if criterion.call
|
16
|
+
rescue
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module WithReminders
|
2
2
|
extend ActiveSupport::Concern
|
3
|
+
include WithPgLock
|
3
4
|
|
4
5
|
def build_reminder
|
5
6
|
mailer = UserMailer.new
|
@@ -18,23 +19,13 @@ module WithReminders
|
|
18
19
|
end
|
19
20
|
|
20
21
|
# Try to send a reminder, by acquiring a database lock for update
|
21
|
-
# the
|
22
|
+
# the appropriate record. This object can't be updated as long as
|
22
23
|
# the reminder is being sent.
|
23
24
|
#
|
24
25
|
# This method is aimed to be sent across multiple servers or processed concurrently
|
25
26
|
# and still not send duplicate mails
|
26
27
|
def try_remind_with_lock!
|
27
|
-
|
28
|
-
#
|
29
|
-
# * nowait is a postgre specific option and may not work with other databases
|
30
|
-
# * nowait will raise an exception if the lock can not be acquired
|
31
|
-
# * we are using a double check lock pattern to reduce lock acquisition
|
32
|
-
with_lock('for update nowait') do
|
33
|
-
reload
|
34
|
-
remind! if should_remind?
|
35
|
-
end if should_remind?
|
36
|
-
rescue
|
37
|
-
nil
|
28
|
+
with_pg_lock proc { remind! }, proc { should_remind? }
|
38
29
|
end
|
39
30
|
|
40
31
|
private
|
@@ -21,7 +21,7 @@ class ExamAuthorizationRequest < ApplicationRecord
|
|
21
21
|
def icon
|
22
22
|
case status.to_sym
|
23
23
|
when :pending
|
24
|
-
{ class: '
|
24
|
+
{ class: 'hourglass', type: 'info' }
|
25
25
|
when :approved
|
26
26
|
{ class: 'check-circle', type: 'success' }
|
27
27
|
when :rejected
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class ExamRegistration < ApplicationRecord
|
2
|
+
include WithPgLock
|
2
3
|
include WithTimedEnablement
|
3
4
|
include TerminalNavigation
|
4
5
|
|
@@ -16,6 +17,8 @@ class ExamRegistration < ApplicationRecord
|
|
16
17
|
|
17
18
|
alias_attribute :name, :description
|
18
19
|
|
20
|
+
scope :should_process, -> { where(processed: false).where(arel_table[:end_time].lt(Time.now)) }
|
21
|
+
|
19
22
|
def authorization_criterion
|
20
23
|
@authorization_criterion ||= ExamRegistration::AuthorizationCriterion.parse(authorization_criterion_type, authorization_criterion_value)
|
21
24
|
end
|
@@ -40,11 +43,21 @@ class ExamRegistration < ApplicationRecord
|
|
40
43
|
registrees.where.not(id: Notification.notified_users_ids_for(self, self.organization))
|
41
44
|
end
|
42
45
|
|
46
|
+
# Try to process authorization request, by acquiring a database lock for update
|
47
|
+
# the appropriate record.
|
48
|
+
#
|
49
|
+
# This method is aimed to be sent across multiple servers or processed concurrently
|
50
|
+
# and still not send duplicate mails
|
43
51
|
def process_requests!
|
52
|
+
with_pg_lock proc { process_authorization_requests! }, proc { !processed? }
|
53
|
+
end
|
54
|
+
|
55
|
+
def process_authorization_requests!
|
44
56
|
authorization_requests.each do |it|
|
45
57
|
process_request! it
|
46
58
|
it.try_authorize!
|
47
59
|
end
|
60
|
+
update! processed: true
|
48
61
|
end
|
49
62
|
|
50
63
|
def authorization_request_for(user)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mumuki-domain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.
|
4
|
+
version: 9.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franco Leonardo Bulgarelli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -291,6 +291,7 @@ files:
|
|
291
291
|
- app/models/concerns/with_name.rb
|
292
292
|
- app/models/concerns/with_notifications.rb
|
293
293
|
- app/models/concerns/with_number.rb
|
294
|
+
- app/models/concerns/with_pg_lock.rb
|
294
295
|
- app/models/concerns/with_preferences.rb
|
295
296
|
- app/models/concerns/with_profile.rb
|
296
297
|
- app/models/concerns/with_progress.rb
|
@@ -666,6 +667,7 @@ files:
|
|
666
667
|
- db/migrate/20210318194559_add_dates_to_certificate_program.rb
|
667
668
|
- db/migrate/20210318195238_rename_certificate_dates.rb
|
668
669
|
- db/migrate/20210330175706_create_exam_registration_user_join_table.rb
|
670
|
+
- db/migrate/20210512200453_add_processed_flag_to_exam_registration.rb
|
669
671
|
- lib/mumuki/domain.rb
|
670
672
|
- lib/mumuki/domain/area.rb
|
671
673
|
- lib/mumuki/domain/engine.rb
|