File tree Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,10 @@ module ActiveInteraction::Extras::ActiveJob
88 def configured_job_class
99 ConfiguredJob
1010 end
11+
12+ def perform_inline ( &block )
13+ job_class . perform_inline ( &block )
14+ end
1115 end
1216
1317 module Perform
@@ -22,15 +26,37 @@ def perform(*args)
2226 end
2327 end
2428 end
29+
30+ class_methods do
31+ def perform_now
32+ Thread . current [ name ] ||= [ ]
33+ Thread . current [ name ] . push true
34+ yield
35+ ensure
36+ if Thread . current [ name ] . size == 1
37+ Thread . current [ name ] = nil
38+ else
39+ Thread . current [ name ] . pop
40+ end
41+ end
42+
43+ def perform_now?
44+ Thread . current [ name ]
45+ end
46+ end
2547 end
2648
2749 class ConfiguredJob < ::ActiveJob ::ConfiguredJob
2850 def run ( *args )
29- perform_later ( *args )
51+ run! ( *args )
3052 end
3153
3254 def run! ( *args )
33- perform_later ( *args )
55+ if @job_class . perform_now?
56+ perform_now ( *args )
57+ else
58+ perform_later ( *args )
59+ end
3460 end
3561 end
3662end
You can’t perform that action at this time.
0 commit comments