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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78fd84c0df628d66cf2ae1ee9776fbdce89015c8d0451723662f60caa2893995
4
- data.tar.gz: 610a113b4434bc52a215b707930fc6accb9a0cbe7cdc1a4e2b4b3bbdaef616cd
3
+ metadata.gz: b6480a8cab348b66eb9f4987d4c56ee773faf649d9cfd937434a6afd3f822ac3
4
+ data.tar.gz: 4f2bc2289286be83807973409daee4f845faca070abaae9f383326b38cef5f4e
5
5
  SHA512:
6
- metadata.gz: 218f4858fb6583b7a86efcaec1f6fa37010c0829c431df05371d69ed433917905a5c7b42ab58b8893fdb2795006f73325392104181d40e3e57441ae316d3d6a7
7
- data.tar.gz: 42576dbb7026b7b034ac80334090386d0a40763b05b7eaa26e765efb389120e59b450e759b3c548271f395fa632ab7bb51bd31feca9771fa282f77e6a27674de
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
- facio_perform_without_arguments
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Facio
4
- VERSION = "0.1.13"
4
+ VERSION = "0.1.15"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom de Grunt