demo_mode 3.7.2 → 3.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/jobs/demo_mode/account_generation_job.rb +8 -2
- data/app/models/demo_mode/session.rb +28 -4
- data/lib/demo_mode/persona.rb +21 -2
- data/lib/demo_mode/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7e73fd7fddd766bef9d1545a62dc2ddd66afc0b8b9c54520eaaf0a565133b475
|
|
4
|
+
data.tar.gz: a4738c449db124a9a0bcd78f75ef4f5d3a0f5de70bc3d841ef42b8e602f3d971
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 74f400f23e3c529a3b928861a6870ac5b39e234cd0fa69174bd88176bb6ac416518a46b390d78dd4a671958b164dd2aa4fabc95a557c051b6835e70f4a555d2d
|
|
7
|
+
data.tar.gz: 06d3c2e5dd2dd757b11c3195124ec237839b56f68f46b693b8cde88c5d7875fdf21bd19333e732ca9c0cd49e8848c112cf9d95e8fa5abba6b57e09c09dc08fd9
|
|
@@ -3,14 +3,20 @@
|
|
|
3
3
|
module DemoMode
|
|
4
4
|
class AccountGenerationJob < DemoMode.base_job_name.constantize
|
|
5
5
|
def perform(session, **options)
|
|
6
|
-
session.with_lock do
|
|
6
|
+
session.with_lock(requires_new: true) do
|
|
7
7
|
session.update!(status: 'processing') if session.failed?
|
|
8
8
|
persona = session.persona
|
|
9
9
|
raise "Unknown persona: #{session.persona_name}" if persona.blank?
|
|
10
10
|
|
|
11
11
|
signinable = persona.generate!(variant: session.variant, password: session.signinable_password, options: options)
|
|
12
|
+
session.update!(signinable: signinable, persona_checksum: persona.file_checksum)
|
|
13
|
+
|
|
14
|
+
if session.claimed_at?
|
|
15
|
+
persona.effective_at_claim_callback(session.variant)&.call(signinable)
|
|
16
|
+
end
|
|
17
|
+
|
|
12
18
|
new_status = session.claimed_at? ? 'in_use' : 'available'
|
|
13
|
-
session.update!(
|
|
19
|
+
session.update!(status: new_status)
|
|
14
20
|
end
|
|
15
21
|
rescue StandardError => e
|
|
16
22
|
session.update!(status: 'failed')
|
|
@@ -14,7 +14,7 @@ module DemoMode
|
|
|
14
14
|
state 'processing', default: true, from: 'failed'
|
|
15
15
|
state 'available', from: 'processing'
|
|
16
16
|
state 'in_use', from: %w(processing available)
|
|
17
|
-
state 'failed', from:
|
|
17
|
+
state 'failed', from: %w(processing available)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
scope :unclaimed, -> { where(claimed_at: nil) }
|
|
@@ -56,13 +56,15 @@ module DemoMode
|
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
def self.claim_for(persona_name:, variant: DEFAULT_VARIANT, **generation_opts)
|
|
59
|
+
persona = DemoMode.personas.find { |p| p.name.to_s == persona_name.to_s && p.variants.key?(variant) }
|
|
59
60
|
pool_hit = false
|
|
60
61
|
session = transaction do
|
|
61
62
|
existing = available_for(persona_name, variant).lock.first
|
|
62
63
|
pool_hit = existing.present?
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
if existing
|
|
65
|
+
claim_pool_session(existing, persona, variant)
|
|
66
|
+
else
|
|
67
|
+
new_claimed_session(persona_name, variant, generation_opts)
|
|
66
68
|
end
|
|
67
69
|
end
|
|
68
70
|
ActiveSupport::Notifications.instrument('demo_mode.session.claimed',
|
|
@@ -70,6 +72,28 @@ module DemoMode
|
|
|
70
72
|
session
|
|
71
73
|
end
|
|
72
74
|
|
|
75
|
+
class << self
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def claim_pool_session(session, persona, variant)
|
|
79
|
+
transaction(requires_new: true) do
|
|
80
|
+
persona&.effective_at_claim_callback(variant)&.call(session.signinable)
|
|
81
|
+
session.claim!
|
|
82
|
+
rescue StandardError
|
|
83
|
+
raise ActiveRecord::Rollback
|
|
84
|
+
end
|
|
85
|
+
session.update!(status: 'failed') unless session.claimed_at?
|
|
86
|
+
session
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def new_claimed_session(persona_name, variant, generation_opts)
|
|
90
|
+
new(persona_name: persona_name, variant: variant).tap do |s|
|
|
91
|
+
s.claim!
|
|
92
|
+
AccountGenerationJob.perform_later(s, **generation_opts) if s.signinable.blank?
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
73
97
|
def claim!
|
|
74
98
|
if new_record?
|
|
75
99
|
self.claimed_at = Time.zone.now
|
data/lib/demo_mode/persona.rb
CHANGED
|
@@ -68,13 +68,17 @@ module DemoMode
|
|
|
68
68
|
variant = variants[variant]
|
|
69
69
|
CleverSequence.reset! if defined?(CleverSequence)
|
|
70
70
|
DemoMode.current_password = password if password
|
|
71
|
-
|
|
71
|
+
ActiveRecord::Base.transaction(requires_new: true) do
|
|
72
|
+
DemoMode.around_persona_generation.call(variant.signinable_generator, **options)
|
|
73
|
+
end
|
|
72
74
|
rescue ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid => e
|
|
73
75
|
raise if retried || !should_retry_with_sequence_adjustment?(e)
|
|
74
76
|
|
|
75
77
|
retried = true
|
|
76
78
|
CleverSequence.with_sequence_adjustment do
|
|
77
|
-
|
|
79
|
+
ActiveRecord::Base.transaction(requires_new: true) do
|
|
80
|
+
DemoMode.around_persona_generation.call(variant.signinable_generator, **options)
|
|
81
|
+
end
|
|
78
82
|
end
|
|
79
83
|
ensure
|
|
80
84
|
DemoMode.current_password = nil
|
|
@@ -97,6 +101,16 @@ module DemoMode
|
|
|
97
101
|
@enabled_condition ? @enabled_condition.call : true
|
|
98
102
|
end
|
|
99
103
|
|
|
104
|
+
def at_claim(&block)
|
|
105
|
+
@at_claim_callback = block
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
attr_reader :at_claim_callback
|
|
109
|
+
|
|
110
|
+
def effective_at_claim_callback(variant_name)
|
|
111
|
+
variants[variant_name]&.at_claim_callback || @at_claim_callback
|
|
112
|
+
end
|
|
113
|
+
|
|
100
114
|
def callout(callout = true) # rubocop:disable Style/OptionalBooleanParameter
|
|
101
115
|
@callout = callout
|
|
102
116
|
end
|
|
@@ -154,10 +168,15 @@ module DemoMode
|
|
|
154
168
|
@enabled_condition ? @enabled_condition.call : true
|
|
155
169
|
end
|
|
156
170
|
|
|
171
|
+
def at_claim(&block)
|
|
172
|
+
@at_claim_callback = block
|
|
173
|
+
end
|
|
174
|
+
|
|
157
175
|
def title
|
|
158
176
|
name.is_a?(Symbol) ? name.to_s.titleize : name.to_s
|
|
159
177
|
end
|
|
160
178
|
|
|
179
|
+
attr_reader :at_claim_callback
|
|
161
180
|
attr_reader :signinable_generator
|
|
162
181
|
end
|
|
163
182
|
end
|
data/lib/demo_mode/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: demo_mode
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.8.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan Griffith
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-05-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionpack
|