facio 0.1.13 → 0.1.15
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/lib/facio/concerns/execution.rb +25 -1
- data/lib/facio/service.rb +14 -1
- data/lib/facio/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b6480a8cab348b66eb9f4987d4c56ee773faf649d9cfd937434a6afd3f822ac3
|
|
4
|
+
data.tar.gz: 4f2bc2289286be83807973409daee4f845faca070abaae9f383326b38cef5f4e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b685cee0737c95408dd2a5199e76f510f525339464dc104a5d97706c5d0309222b5bc2bb205cea818be77ec2358deb817d54bafa26e4ba389840f020f164c7e3
|
|
7
|
+
data.tar.gz: 544bff591787982d6249968921a919a3396cc13d8c56197b94aaceb32a2a9f7ebc656b5530db112dd7ef6dc42c602502fb8992b465f1de6bbe3149c3d274b5e2
|
|
@@ -1,8 +1,32 @@
|
|
|
1
1
|
module Execution
|
|
2
2
|
extend ActiveSupport::Concern
|
|
3
3
|
|
|
4
|
+
# Facio doesn't support arguments in the perform method, that's done with the context object.
|
|
5
|
+
# This is why we override perform here.
|
|
4
6
|
def facio_perform_with_arguments(*args)
|
|
5
|
-
|
|
7
|
+
@context = self.class.context_class.new(arguments.first)
|
|
8
|
+
@result = self.class.result_class&.new
|
|
9
|
+
@performed = false
|
|
10
|
+
|
|
11
|
+
if @context.valid?
|
|
12
|
+
result = nil
|
|
13
|
+
if transactional && defined?(ActiveRecord::Base)
|
|
14
|
+
ActiveRecord::Base.transaction(requires_new: true) do
|
|
15
|
+
# result = block.call
|
|
16
|
+
result = facio_perform_without_arguments
|
|
17
|
+
# This will only rollback the changes of the service, SILENTLY, however the context will be failed? already.
|
|
18
|
+
# This is the most close to expected behaviour this can get.
|
|
19
|
+
raise ActiveRecord::Rollback if context.failed?
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
else
|
|
23
|
+
result = facio_perform_without_arguments
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
@performed = true
|
|
27
|
+
# Purely as a convenience, but also to enforce a standard
|
|
28
|
+
context.result ||= result if @result.nil?
|
|
29
|
+
end
|
|
6
30
|
end
|
|
7
31
|
|
|
8
32
|
included do
|
data/lib/facio/service.rb
CHANGED
|
@@ -11,7 +11,6 @@ module Facio
|
|
|
11
11
|
include ServiceResult
|
|
12
12
|
include Transactional
|
|
13
13
|
include Translations
|
|
14
|
-
include Callbacks
|
|
15
14
|
include Execution
|
|
16
15
|
|
|
17
16
|
class << self
|
|
@@ -21,6 +20,20 @@ module Facio
|
|
|
21
20
|
job
|
|
22
21
|
end
|
|
23
22
|
|
|
23
|
+
def perform_later(...)
|
|
24
|
+
job = job_or_instantiate(...)
|
|
25
|
+
|
|
26
|
+
enqueue_result = job.enqueue
|
|
27
|
+
|
|
28
|
+
job.instance_variable_set(:@performed, false)
|
|
29
|
+
job.instance_variable_set(:@context, context_class.new(job.arguments.first))
|
|
30
|
+
job.instance_variable_set(:@result, result_class&.new)
|
|
31
|
+
|
|
32
|
+
yield job if block_given?
|
|
33
|
+
|
|
34
|
+
enqueue_result
|
|
35
|
+
end
|
|
36
|
+
|
|
24
37
|
alias_method :perform_now, :perform
|
|
25
38
|
end
|
|
26
39
|
|
data/lib/facio/version.rb
CHANGED