isomorfeus-operation 2.5.5 → 22.9.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88039cb23105a0035cee17b77b44dac75936618387151e7088f6dcaa51669003
4
- data.tar.gz: c12f46a8e826503a0c1369a9699ef5360b1d11e8788e1d238084bd3f49c34793
3
+ metadata.gz: ed8b7a6bb38fd8be23ca7700ace4406d1935c1293e989a067d6d90fa4094494f
4
+ data.tar.gz: 7143a91a4aeec61783850017f4e9f5350256aca9704aa52d02d15c447e0f54be
5
5
  SHA512:
6
- metadata.gz: 0b9b7b8e34b84ca00227c7705e55d72b2338421069b5ff5373cfbbf717f8ccdec01e25036827b4ff47337af809f21a237116216765abf63e1478d039d13b3e43
7
- data.tar.gz: 9d74af0f5c3816564e2d2ed70193d53f75bd87cf201a9a7daa277600199c17f6476965c1ea626047f638355c66b7b98712d26b5c517e9895b485d28bcd7e20c0
6
+ metadata.gz: 55667be961cac8cc70f2e4089549f1e3ac358b4a69307f8cb08d224c91052eecb2a28400c9a21e85b9d39fd0e948e0ef3428a871a5dae5ad6346e065d1241372
7
+ data.tar.gz: d741a0fea05377857ed1fba3d1a6247ceecff187f6cc2ce610a20912c0f8cbe32a6654f4145451800f4356f10753e9a9f617232d310e763e78b97e756dbf04a4
@@ -30,7 +30,7 @@ module Isomorfeus
30
30
  def pop_failed_tasks
31
31
  failed_tasks = []
32
32
  [Isomorfeus::Operation::DeferredTask, Isomorfeus::Operation::DailyTask].each do |task_class|
33
- task_class.search(:state, 'failed').each do |task|
33
+ task_class.search(:failed).each do |task|
34
34
  failed_tasks << task
35
35
  task.destroy
36
36
  end
@@ -41,7 +41,7 @@ module Isomorfeus
41
41
  def all_tasks
42
42
  all_tasks = []
43
43
  [Isomorfeus::Operation::DeferredTask, Isomorfeus::Operation::DailyTask].each do |task_class|
44
- task_class.search(:state, '*').each do |task|
44
+ task_class.search(:all).each do |task|
45
45
  all_tasks << task
46
46
  end
47
47
  end
@@ -1,7 +1,13 @@
1
1
  module Isomorfeus
2
2
  module Operation
3
- class DailyTask < LucidObject::Base
3
+ class DailyTask < LucidObject
4
4
  STATES = %w[ready running failed]
5
+
6
+ query :ready, 'state:"ready"'
7
+ query :running, 'state:"running"'
8
+ query :failed, 'state:"failed"'
9
+ query :all, 'state:*'
10
+
5
11
  # when the task is added to the queue its added as ready
6
12
  # when its running, its running
7
13
  # when it failes, it failed, the exception attribute is filled
@@ -1,7 +1,13 @@
1
1
  module Isomorfeus
2
2
  module Operation
3
- class DeferredTask < LucidObject::Base
3
+ class DeferredTask < LucidObject
4
4
  STATES = %w[ready running failed]
5
+
6
+ query :ready, 'state:"ready"'
7
+ query :running, 'state:"running"'
8
+ query :failed, 'state:"failed"'
9
+ query :all, 'state:*'
10
+
5
11
  # when the task is added to the queue its added as ready
6
12
  # when its running, its running
7
13
  # when it failes, it failed, the exception attribute is filled
@@ -28,13 +28,13 @@ module Isomorfeus
28
28
 
29
29
  def promise_run(**props_hash)
30
30
  props = validated_props(props_hash)
31
- Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.name, :run, props)
31
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler', self.name, :run, props)
32
32
  .then { |agent| _process_response(agent) }
33
33
  end
34
34
 
35
35
  def promise_deferred(**props_hash)
36
36
  props = validated_props(props_hash)
37
- Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.name, :deferred, props)
37
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler', self.name, :deferred, props)
38
38
  .then { |agent| _process_response(agent) }
39
39
  end
40
40
 
@@ -42,19 +42,17 @@ module Isomorfeus
42
42
  key = props_hash.delete(:key)
43
43
  props = validated_props(props_hash)
44
44
  props[:key] = key if key
45
- Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.name, :daily, props)
45
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler', self.name, :daily, props)
46
46
  .then { |agent| _process_response(agent) }
47
47
  end
48
48
 
49
- def promise_remove_daily(**props_hash)
50
- raise "key: must be given" unless props_hash.key?(:key)
51
- Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.name, :remove_daily, props_hash)
49
+ def promise_remove_daily(key:)
50
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler', self.name, :remove_daily, key: key)
52
51
  .then { |agent| _process_response(agent) }
53
52
  end
54
53
 
55
- def promise_daily_exist?(**props_hash)
56
- raise "key: must be given" unless props_hash.key?(:key)
57
- Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.name, :daily_exist, props_hash)
54
+ def promise_daily_exist?(key:)
55
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler', self.name, :daily_exist, key: key)
58
56
  .then { |agent| _process_response(agent) }
59
57
  end
60
58
  else
@@ -75,17 +73,13 @@ module Isomorfeus
75
73
  Promise.new.resolve(task.key)
76
74
  end
77
75
 
78
- def promise_remove_daily(**props_hash)
79
- raise "key: must be given" unless props_hash.key?(:key)
80
- key = props_hash.delete(:key)
76
+ def promise_remove_daily(key:)
81
77
  Isomorfeus::Operation::DailyTask.destroy(key: key)
82
78
  Promise.new.resolve(true)
83
79
  end
84
80
 
85
- def promise_daily_exist?(**props_hash)
86
- raise "key: must be given" unless props_hash.key?(:key)
87
- key = props_hash.delete(:key)
88
- have_task = !!Isomorfeus::Operation::DailyTask.load(key: key)
81
+ def promise_daily_exist?(key:)
82
+ have_task = !!Isomorfeus::Operation::DailyTask.exist?(key: key)
89
83
  Promise.new.resolve(have_task)
90
84
  end
91
85
  end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Isomorfeus
4
+ module Operation
5
+ class Handler < LucidHandler
6
+ on_request do |response_agent|
7
+ # promise_send_path('Isomorfeus::Operation::Handler', self.to_s, props_hash)
8
+ response_agent.request.each_key do |operation_class_name|
9
+ if Isomorfeus.valid_operation_class_name?(operation_class_name)
10
+ operation_class = Isomorfeus.cached_operation_class(operation_class_name)
11
+ if operation_class
12
+ response_agent.request[operation_class_name].each_key do |method|
13
+ props = response_agent.request[operation_class_name][method]
14
+ props.transform_keys!(&:to_sym)
15
+ begin
16
+ case method
17
+ when 'run'
18
+ raise 'Access denied!' unless Isomorfeus.current_user.authorized?(operation_class, :promise_run, props)
19
+ operation_promise = operation_class.promise_run(**props)
20
+ if operation_promise.realized?
21
+ state = operation_promise.resolved? ? :resolved : :rejected
22
+ result_hash = { state => operation_promise.value }
23
+ if operation_promise.error
24
+ e = operation_promise.error
25
+ result_hash[:error] = { message: e.message, class_name: e.class.to_s, back_trace: e.backtrace }
26
+ end
27
+ response_agent.agent_result = { success: 'ok' , result: result_hash }
28
+ else
29
+ start = Time.now
30
+ timeout = false
31
+ while !operation_promise.realized?
32
+ if (Time.now - start) > 20
33
+ timeout = true
34
+ break
35
+ end
36
+ sleep 0.01
37
+ end
38
+ if timeout
39
+ response_agent.error = { error: 'Timeout' }
40
+ else
41
+ state = operation_promise.resolved? ? :resolved : :rejected
42
+ result_hash = { state => operation_promise.value }
43
+ if operation_promise.error
44
+ e = operation_promise.error
45
+ result_hash[:error] = { message: e.message, class_name: e.class.to_s, back_trace: e.backtrace }
46
+ end
47
+ response_agent.agent_result = { success: 'ok' , result: result_hash }
48
+ end
49
+ end
50
+ when 'deferred'
51
+ raise 'Access denied!' unless Isomorfeus.current_user.authorized?(operation_class, :promise_deferred, props)
52
+ operation_promise = operation_class.promise_deferred(**props)
53
+ response_agent.agent_result = { success: 'ok' , result: { :resolved => operation_promise.value }}
54
+ when 'daily'
55
+ raise 'Access denied!' unless Isomorfeus.current_user.authorized?(operation_class, :promise_daily, props)
56
+ operation_promise = operation_class.promise_daily(**props)
57
+ response_agent.agent_result = { success: 'ok' , result: { :resolved => operation_promise.value }}
58
+ when 'remove_daily'
59
+ raise 'Access denied!' unless Isomorfeus.current_user.authorized?(operation_class, :promise_daily, props)
60
+ operation_promise = operation_class.promise_remove_daily(**props)
61
+ response_agent.agent_result = { success: 'ok' , result: { :resolved => operation_promise.value }}
62
+ when 'daily_exist'
63
+ raise 'Access denied!' unless Isomorfeus.current_user.authorized?(operation_class, :promise_daily, props)
64
+ operation_promise = operation_class.promise_daily(**props)
65
+ response_agent.agent_result = { success: 'ok' , result: { :resolved => operation_promise.value }}
66
+ else
67
+ response_agent.error = { error: 'No such method!' }
68
+ end
69
+ rescue Exception => e
70
+ response_agent.error = { error: { operation_class_name => "Isomorfeus::Operation::Handler: #{e.message}" }}
71
+ end
72
+ end
73
+ else
74
+ response_agent.error = { error: { operation_class_name => 'Could not get operation class!' }}
75
+ end
76
+ else
77
+ response_agent.error = { error: { operation_class_name => 'No such operation class!' }}
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -8,6 +8,6 @@ Isomorfeus.operation_timer_tasks[:daily] = Concurrent::TimerTask.new(execution_i
8
8
  Isomorfeus::Operation::RunTask.new(Isomorfeus::Operation::DailyTask, timer_task: timer_task, interval: 86400, recurring: true).run
9
9
  end
10
10
 
11
- Isomorfeus.operation_timer_tasks.each do |k, t|
11
+ Isomorfeus.operation_timer_tasks.each_value do |t|
12
12
  t.execute
13
13
  end
@@ -9,29 +9,41 @@ module Isomorfeus
9
9
  end
10
10
 
11
11
  def run
12
+ Isomorfeus.init_store
13
+ Isomorfeus.store.clear!
12
14
  @rtime = Time.now
13
15
  tasks = get_tasks
14
16
  tasks.each do |task|
15
17
  marked = mark_as_running(task)
16
18
  if marked
17
19
  begin
18
- operation_class = task.operation_class_name.constantize
19
- user_class_name = task.user_class_name
20
- Thread.current[:isomorfeus_user] = if user_class_name == 'LocalSystem'
21
- LocalSystem.new
22
- elsif Isomorfeus.valid_user_class_name?(user_class_name)
23
- user_class = user_class_name.constantize
24
- user_class.load(key: task.user_key) || Anonymous.new
25
- else
26
- Anonymous.new
27
- end
28
- raise 'Access denied!' unless Thread.current[:isomorfeus_user].authorized?(operation_class, :promise_run, task.props)
20
+ operation_class = task[:operation_class_name].constantize
21
+ user_class_name = task[:user_class_name]
22
+ user_instance = if user_class_name == 'LocalSystem'
23
+ LocalSystem.new
24
+ elsif user_class_name == 'Anonymous'
25
+ Anonymous.new
26
+ elsif Isomorfeus.valid_user_class_name?(user_class_name)
27
+ user_class = user_class_name.constantize
28
+ cu = Thread.current[:isomorfeus_user]
29
+ Thread.current[:isomorfeus_user] = LocalSystem.new
30
+ begin
31
+ u = user_class.load(key: task[:user_key]) || Anonymous.new
32
+ ensure
33
+ Thread.current[:isomorfeus_user] = cu
34
+ end
35
+ u
36
+ else
37
+ Anonymous.new
38
+ end
39
+ Thread.current[:isomorfeus_user] = user_instance
40
+ raise 'Access denied!' unless Thread.current[:isomorfeus_user].authorized?(operation_class, :promise_run, task[:props])
29
41
  if @recurring
30
- operation_class.promise_run(**task.props)
42
+ operation_class.promise_run(**task[:props])
31
43
  .then { mark_as_ready(task) }
32
- .fail { |e| task.fail ? mark_as_failed(task, e) : save_exception(task, e) }
44
+ .fail { |e| task[:fail] ? mark_as_failed(task, e) : save_exception(task, e) }
33
45
  else
34
- operation_class.promise_run(**task.props)
46
+ operation_class.promise_run(**task[:props])
35
47
  .then { remove_task(task) }
36
48
  .fail { |e| mark_as_failed(task, e) }
37
49
  end
@@ -47,46 +59,83 @@ module Isomorfeus
47
59
  end
48
60
 
49
61
  def get_tasks
50
- @task_class.search(:state, 'ready').sort_by! { |task| task.rtime.to_i }
62
+ begin
63
+ Thread.current[:isomorfeus_user] = LocalSystem.new
64
+
65
+ result = @task_class.search(:ready).sort_by! { |task| task[:rtime] ? Time.parse(task[:rtime]).to_i : 0 }
66
+ ensure
67
+ Thread.current[:isomorfeus_user] = nil
68
+ end
69
+ result
51
70
  end
52
71
 
53
72
  def mark_as_running(task)
54
- result = false
55
- task = @task_class.load(key: task.key)
56
- if task && (task.rtime.nil? || (task.rtime - @rtime) >= @timer_task.execution_interval) && task.state == 'ready'
57
- task.state = 'running'
58
- task.rtime = @rtime
59
- task.save
60
- result = true
73
+ begin
74
+ Thread.current[:isomorfeus_user] = LocalSystem.new
75
+
76
+ task = @task_class.load(key: task.key)
77
+ trt = task[:rtime] ? Time.parse(task[:rtime]) : nil
78
+ result = false
79
+ if task && (trt.nil? || (trt - @rtime) >= @timer_task.execution_interval) && task[:state] == 'ready'
80
+ task[:state] = 'running'
81
+ task[:rtime] = @rtime.to_s
82
+ task.save
83
+ result = true
84
+ end
85
+ ensure
86
+ Thread.current[:isomorfeus_user] = nil
61
87
  end
62
88
  result
63
89
  end
64
90
 
65
91
  def mark_as_ready(task)
66
- task.state = 'ready'
92
+ Thread.current[:isomorfeus_user] = LocalSystem.new
93
+
94
+ task[:state] = 'ready'
67
95
  task.save
96
+ ensure
97
+ Thread.current[:isomorfeus_user] = nil
68
98
  end
69
99
 
70
100
  def mark_as_failed(task, exception)
71
- task.state = 'failed'
101
+ Thread.current[:isomorfeus_user] = LocalSystem.new
102
+
103
+ task[:state] = 'failed'
72
104
  save_exception(task, exception)
105
+ ensure
106
+ Thread.current[:isomorfeus_user] = nil
73
107
  end
74
108
 
75
- def save_exception(taks, exception)
76
- task.exception = Marshal.dump(exception)
109
+ def save_exception(task, exception)
110
+ Thread.current[:isomorfeus_user] = LocalSystem.new
111
+
112
+ task[:exception] = Marshal.dump(exception)
77
113
  task.save
114
+ ensure
115
+ Thread.current[:isomorfeus_user] = nil
78
116
  end
79
117
 
80
118
  def remove_task(task)
119
+ Thread.current[:isomorfeus_user] = LocalSystem.new
120
+
81
121
  @task_class.destroy(key: task.key)
122
+ ensure
123
+ Thread.current[:isomorfeus_user] = nil
82
124
  end
83
125
 
84
126
  def cleanup
85
- running_tasks = @task_class.search(:state, 'running').sort_by! { |task| task.rtime.to_i }
127
+ Thread.current[:isomorfeus_user] = LocalSystem.new
128
+
129
+ running_tasks = @task_class.search(:running).sort_by! do |task|
130
+ task[:rtime] ? Time.parse(task[:rtime]).to_i : 0
131
+ end
86
132
  running_tasks.each do |task|
87
133
  # previous task run has timed out most probably
88
- mark_as_failed(task, RuntimeError.new('Operation execution timed out, giving up.')) if (@rtime - task.rtime) > @interval
134
+ trt = task[:rtime] ? Time.parse(task[:rtime]) : 0
135
+ mark_as_failed(task, RuntimeError.new('Operation execution timed out, giving up.')) if (@rtime - trt) > @interval
89
136
  end
137
+ ensure
138
+ Thread.current[:isomorfeus_user] = nil
90
139
  end
91
140
  end
92
141
  end
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module Operation
3
- VERSION = '2.5.5'
3
+ VERSION = '22.9.0.rc2'
4
4
  end
5
5
  end
@@ -1,27 +1,21 @@
1
- require 'isomorfeus-policy'
2
1
  require 'isomorfeus-transport'
3
-
2
+ require 'isomorfeus-policy'
4
3
  require 'isomorfeus/operation/config'
5
4
  require 'isomorfeus/operation/generic_class_api'
5
+ require 'lucid_operation/gherkin'
6
+ require 'lucid_operation/steps'
7
+ require 'lucid_operation/promise_run'
8
+ require 'lucid_local_operation'
9
+ require 'lucid_simple_operation'
10
+ require 'lucid_operation'
6
11
 
7
12
  if RUBY_ENGINE == 'opal'
8
- Isomorfeus.zeitwerk.push_dir('isomorfeus_operation')
9
- require_tree 'isomorfeus_operation', autoload: true
10
13
  Isomorfeus.zeitwerk.push_dir('operations')
11
14
  else
12
15
  require 'oj'
13
16
  require 'concurrent/timer_task'
14
17
  require 'isomorfeus-data'
15
- require 'isomorfeus/operation/handler/operation_handler'
16
- require 'isomorfeus_operation/lucid_operation/gherkin'
17
- require 'isomorfeus_operation/lucid_operation/steps'
18
- require 'isomorfeus_operation/lucid_operation/promise_run'
19
- require 'isomorfeus_operation/lucid_local_operation/mixin'
20
- require 'isomorfeus_operation/lucid_local_operation/base'
21
- require 'isomorfeus_operation/lucid_simple_operation/mixin'
22
- require 'isomorfeus_operation/lucid_simple_operation/base'
23
- require 'isomorfeus_operation/lucid_operation/mixin'
24
- require 'isomorfeus_operation/lucid_operation/base'
18
+ require 'isomorfeus/operation/handler'
25
19
  require 'isomorfeus/operation/deferred_task'
26
20
  require 'isomorfeus/operation/daily_task'
27
21
  require 'isomorfeus/operation/run_task'
@@ -31,6 +25,5 @@ else
31
25
  Opal.append_path(__dir__.untaint) unless IsoOpal.paths.include?(__dir__.untaint)
32
26
 
33
27
  path = File.expand_path(File.join('app', 'operations'))
34
-
35
- Isomorfeus.zeitwerk.push_dir(path)
28
+ Isomorfeus.zeitwerk.push_dir(path) if Dir.exist?(path)
36
29
  end
@@ -0,0 +1,32 @@
1
+ class LucidLocalOperation
2
+ extend Preact::PropDeclarationMixin
3
+ extend LucidOperation::Steps
4
+ include LucidOperation::PromiseRun
5
+
6
+ class << self
7
+ if RUBY_ENGINE != 'opal'
8
+ def inherited(base)
9
+ Isomorfeus.add_valid_operation_class(base)
10
+ end
11
+ end
12
+
13
+ def promise_run(**props_hash)
14
+ self.new(**props_hash).promise_run
15
+ end
16
+ end
17
+
18
+ attr_reader :props
19
+ attr_accessor :step_result
20
+
21
+ def initialize(**props_hash)
22
+ @props = self.class.validated_props(props_hash)
23
+ end
24
+
25
+ def current_user
26
+ Isomorfeus.current_user
27
+ end
28
+
29
+ def pub_sub_client
30
+ Isomorfeus.pub_sub_client
31
+ end
32
+ end
@@ -1,4 +1,4 @@
1
- module LucidOperation
1
+ class LucidOperation
2
2
  module Gherkin
3
3
  FIRST_EXCEPTION = "First must be the first one that is used and can only used once!"
4
4
  FINALLY_EXCEPTION = "Finally, except for Ensure and Failed, must be the last one to be used and can only be used once!"
@@ -1,4 +1,4 @@
1
- module LucidOperation
1
+ class LucidOperation
2
2
  module PromiseRun
3
3
  def promise_run
4
4
  promise = Promise.new
@@ -1,6 +1,4 @@
1
- # frozen_string_literal: true
2
-
3
- module LucidOperation
1
+ class LucidOperation
4
2
  module Steps
5
3
  def procedure(gherkin_text)
6
4
  feature_line = gherkin_text.include?('Operation: ') ? '' : "Operation: #{self.name}\n"
@@ -24,32 +22,37 @@ module LucidOperation
24
22
  @steps ||= []
25
23
  end
26
24
 
27
- def First(regular_expression, &block)
25
+ def First(regexp_or_string, &block)
28
26
  Isomorfeus.raise_error(message: "#{self}: First already defined, can only be defined once!") if @first_defined
29
27
  @first_defined = true
30
- steps << [regular_expression, block]
28
+ steps << [_re_from_res(regexp_or_string), block]
31
29
  end
32
30
 
33
- def Given(regular_expression, &block)
34
- steps << [regular_expression, block]
31
+ def Given(regexp_or_string, &block)
32
+ steps << [_re_from_res(regexp_or_string), block]
35
33
  end
36
34
  alias :And :Given
37
35
  alias :Then :Given
38
36
  alias :When :Given
39
37
 
40
- def Finally(regular_expression, &block)
38
+ def Finally(regexp_or_string, &block)
41
39
  Isomorfeus.raise_error(message: "#{self}: Finally already defined, can only be defined once!") if @finally_defined
42
40
  @finally_defined = true
43
- steps << [regular_expression, block]
41
+ steps << [_re_from_res(regexp_or_string), block]
42
+ end
43
+
44
+ def Ensure(regexp_or_string, &block)
45
+ ensure_steps << [_re_from_res(regexp_or_string), block]
44
46
  end
45
47
 
46
- def Ensure(regular_expression, &block)
47
- ensure_steps << [regular_expression, block]
48
+ def Failed(regexp_or_string, &block)
49
+ failure_steps << [_re_from_res(regexp_or_string), block]
48
50
  end
49
51
 
50
- def Failed(regular_expression, &block)
51
- failure_steps << [regular_expression, block]
52
+ def _re_from_res(regexp_or_string)
53
+ regexp_or_string.is_a?(String) ? Regexp.new(regexp_or_string) : regexp_or_string
52
54
  end
55
+
53
56
  alias :If_failing :Failed
54
57
  alias :When_failing :Failed
55
58
  alias :If_this_failed :Failed
@@ -0,0 +1,49 @@
1
+ class LucidOperation
2
+ extend Preact::PropDeclarationMixin
3
+ extend Isomorfeus::Operation::GenericClassApi
4
+
5
+ if RUBY_ENGINE == 'opal'
6
+ class << self
7
+ def procedure(gherkin_text); end
8
+ def steps; end
9
+
10
+ alias :gherkin :steps
11
+ alias :ensure_steps :steps
12
+ alias :failure_steps :steps
13
+ alias :Given :steps
14
+ alias :And :steps
15
+ alias :Then :steps
16
+ alias :When :steps
17
+ alias :Ensure :steps
18
+ alias :Failed :steps
19
+ alias :If_failing :steps
20
+ alias :When_failing :steps
21
+ alias :If_this_failed :steps
22
+ alias :If_that_failed :steps
23
+ alias :First :steps
24
+ alias :Finally :steps
25
+ end
26
+ else
27
+ extend LucidOperation::Steps
28
+ include LucidOperation::PromiseRun
29
+
30
+ def self.inherited(base)
31
+ Isomorfeus.add_valid_operation_class(base)
32
+ end
33
+
34
+ attr_reader :props
35
+ attr_accessor :step_result
36
+
37
+ def initialize(**props_hash)
38
+ @props = self.class.validated_props(props_hash)
39
+ end
40
+
41
+ def current_user
42
+ Isomorfeus.current_user
43
+ end
44
+
45
+ def pub_sub_client
46
+ Isomorfeus.pub_sub_client
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,44 @@
1
+ class LucidSimpleOperation
2
+ extend Preact::PropDeclarationMixin
3
+ extend Isomorfeus::Operation::GenericClassApi
4
+
5
+ class << self
6
+ if RUBY_ENGINE == 'opal'
7
+ def op; end
8
+ else
9
+ def inherited(base)
10
+ Isomorfeus.add_valid_operation_class(base)
11
+ end
12
+
13
+ def op(&block)
14
+ @op = block
15
+ end
16
+ end
17
+ end
18
+
19
+ attr_reader :props
20
+
21
+ def initialize(**props_hash)
22
+ @props = self.class.validated_props(props_hash)
23
+ end
24
+
25
+ def promise_run
26
+ original_promise = Promise.new
27
+
28
+ operation = self
29
+ promise = original_promise.then do |_|
30
+ operation.instance_exec(&operation.class.instance_variable_get(:@op))
31
+ end
32
+
33
+ original_promise.resolve
34
+ promise
35
+ end
36
+
37
+ def current_user
38
+ Isomorfeus.current_user
39
+ end
40
+
41
+ def pub_sub_client
42
+ Isomorfeus.pub_sub_client
43
+ end
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-operation
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.5
4
+ version: 22.9.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-01 00:00:00.000000000 Z
11
+ date: 2022-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 7.0.2
19
+ version: 7.0.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 7.0.2
26
+ version: 7.0.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: concurrent-ruby
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.13.13
47
+ version: 3.13.21
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.13.13
54
+ version: 3.13.21
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: opal
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.5.0
61
+ version: 1.5.1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.5.0
68
+ version: 1.5.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: opal-activesupport
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,98 +86,98 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.14.24
89
+ version: 0.15.1
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.14.24
96
+ version: 0.15.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: isomorfeus-data
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 2.5.5
103
+ version: 22.9.0.rc2
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 2.5.5
110
+ version: 22.9.0.rc2
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: isomorfeus-policy
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 2.5.5
117
+ version: 22.9.0.rc2
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 2.5.5
124
+ version: 22.9.0.rc2
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: isomorfeus-preact
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 10.7.2
131
+ version: 22.9.0.rc2
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 10.7.2
138
+ version: 22.9.0.rc2
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: isomorfeus-redux
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - '='
144
144
  - !ruby/object:Gem::Version
145
- version: 4.2.0
145
+ version: 22.9.0.rc2
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - "~>"
150
+ - - '='
151
151
  - !ruby/object:Gem::Version
152
- version: 4.2.0
152
+ version: 22.9.0.rc2
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: isomorfeus-transport
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - '='
158
158
  - !ruby/object:Gem::Version
159
- version: 2.5.5
159
+ version: 22.9.0.rc2
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - '='
165
165
  - !ruby/object:Gem::Version
166
- version: 2.5.5
166
+ version: 22.9.0.rc2
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: isomorfeus
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - '='
172
172
  - !ruby/object:Gem::Version
173
- version: 2.5.5
173
+ version: 22.9.0.rc2
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - '='
179
179
  - !ruby/object:Gem::Version
180
- version: 2.5.5
180
+ version: 22.9.0.rc2
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: rake
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -219,19 +219,16 @@ files:
219
219
  - lib/isomorfeus/operation/daily_task.rb
220
220
  - lib/isomorfeus/operation/deferred_task.rb
221
221
  - lib/isomorfeus/operation/generic_class_api.rb
222
- - lib/isomorfeus/operation/handler/operation_handler.rb
222
+ - lib/isomorfeus/operation/handler.rb
223
223
  - lib/isomorfeus/operation/init_timer_tasks.rb
224
224
  - lib/isomorfeus/operation/run_task.rb
225
225
  - lib/isomorfeus/operation/version.rb
226
- - lib/isomorfeus_operation/lucid_local_operation/base.rb
227
- - lib/isomorfeus_operation/lucid_local_operation/mixin.rb
228
- - lib/isomorfeus_operation/lucid_operation/base.rb
229
- - lib/isomorfeus_operation/lucid_operation/gherkin.rb
230
- - lib/isomorfeus_operation/lucid_operation/mixin.rb
231
- - lib/isomorfeus_operation/lucid_operation/promise_run.rb
232
- - lib/isomorfeus_operation/lucid_operation/steps.rb
233
- - lib/isomorfeus_operation/lucid_simple_operation/base.rb
234
- - lib/isomorfeus_operation/lucid_simple_operation/mixin.rb
226
+ - lib/lucid_local_operation.rb
227
+ - lib/lucid_operation.rb
228
+ - lib/lucid_operation/gherkin.rb
229
+ - lib/lucid_operation/promise_run.rb
230
+ - lib/lucid_operation/steps.rb
231
+ - lib/lucid_simple_operation.rb
235
232
  homepage: https://isomorfeus.com
236
233
  licenses:
237
234
  - MIT
@@ -249,9 +246,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
249
246
  version: '0'
250
247
  required_rubygems_version: !ruby/object:Gem::Requirement
251
248
  requirements:
252
- - - ">="
249
+ - - ">"
253
250
  - !ruby/object:Gem::Version
254
- version: '0'
251
+ version: 1.3.1
255
252
  requirements: []
256
253
  rubygems_version: 3.3.7
257
254
  signing_key:
@@ -1,85 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Isomorfeus
4
- module Operation
5
- module Handler
6
- class OperationHandler < LucidHandler::Base
7
- on_request do |response_agent|
8
- # promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.to_s, props_hash)
9
- response_agent.request.each_key do |operation_class_name|
10
- if Isomorfeus.valid_operation_class_name?(operation_class_name)
11
- operation_class = Isomorfeus.cached_operation_class(operation_class_name)
12
- if operation_class
13
- response_agent.request[operation_class_name].each_key do |method|
14
- props = response_agent.request[operation_class_name][method]
15
- props.transform_keys!(&:to_sym)
16
- begin
17
- case method
18
- when 'run'
19
- raise 'Access denied!' unless Isomorfeus.current_user.authorized?(operation_class, :promise_run, props)
20
- operation_promise = operation_class.promise_run(**props)
21
- if operation_promise.realized?
22
- state = operation_promise.resolved? ? :resolved : :rejected
23
- result_hash = { state => operation_promise.value }
24
- if operation_promise.error
25
- e = operation_promise.error
26
- result_hash[:error] = { message: e.message, class_name: e.class.to_s, back_trace: e.backtrace }
27
- end
28
- response_agent.agent_result = { success: 'ok' , result: result_hash }
29
- else
30
- start = Time.now
31
- timeout = false
32
- while !operation_promise.realized?
33
- if (Time.now - start) > 20
34
- timeout = true
35
- break
36
- end
37
- sleep 0.01
38
- end
39
- if timeout
40
- response_agent.error = { error: 'Timeout' }
41
- else
42
- state = operation_promise.resolved? ? :resolved : :rejected
43
- result_hash = { state => operation_promise.value }
44
- if operation_promise.error
45
- e = operation_promise.error
46
- result_hash[:error] = { message: e.message, class_name: e.class.to_s, back_trace: e.backtrace }
47
- end
48
- response_agent.agent_result = { success: 'ok' , result: result_hash }
49
- end
50
- end
51
- when 'deferred'
52
- raise 'Access denied!' unless Isomorfeus.current_user.authorized?(operation_class, :promise_deferred, props)
53
- operation_promise = operation_class.promise_deferred(**props)
54
- response_agent.agent_result = { success: 'ok' , result: { :resolved => operation_promise.value }}
55
- when 'daily'
56
- raise 'Access denied!' unless Isomorfeus.current_user.authorized?(operation_class, :promise_daily, props)
57
- operation_promise = operation_class.promise_daily(**props)
58
- response_agent.agent_result = { success: 'ok' , result: { :resolved => operation_promise.value }}
59
- when 'remove_daily'
60
- raise 'Access denied!' unless Isomorfeus.current_user.authorized?(operation_class, :promise_daily, props)
61
- operation_promise = operation_class.promise_remove_daily(**props)
62
- response_agent.agent_result = { success: 'ok' , result: { :resolved => operation_promise.value }}
63
- when 'daily_exist'
64
- raise 'Access denied!' unless Isomorfeus.current_user.authorized?(operation_class, :promise_daily, props)
65
- operation_promise = operation_class.promise_daily(**props)
66
- response_agent.agent_result = { success: 'ok' , result: { :resolved => operation_promise.value }}
67
- else
68
- response_agent.error = { error: 'No such method!' }
69
- end
70
- rescue Exception => e
71
- response_agent.error = { error: { operation_class_name => "Isomorfeus::Operation::Handler::OperationHandler: #{e.message}" }}
72
- end
73
- end
74
- else
75
- response_agent.error = { error: { operation_class_name => 'Could not get operation class!' }}
76
- end
77
- else
78
- response_agent.error = { error: { operation_class_name => 'No such operation class!' }}
79
- end
80
- end
81
- end
82
- end
83
- end
84
- end
85
- end
@@ -1,10 +0,0 @@
1
- module LucidLocalOperation
2
- class Base
3
- def self.inherited(base)
4
- base.include LucidLocalOperation::Mixin
5
- if RUBY_ENGINE != 'opal'
6
- Isomorfeus.add_valid_operation_class(base)
7
- end
8
- end
9
- end
10
- end
@@ -1,35 +0,0 @@
1
- module LucidLocalOperation
2
- module Mixin
3
- def self.included(base)
4
- if RUBY_ENGINE != 'opal'
5
- Isomorfeus.add_valid_operation_class(base) unless base == LucidLocalOperation::Base
6
-
7
- def pub_sub_client
8
- Isomorfeus.pub_sub_client
9
- end
10
- end
11
-
12
- base.extend(LucidPropDeclaration::Mixin)
13
- base.extend(LucidOperation::Steps)
14
- base.include(LucidOperation::PromiseRun)
15
-
16
- base.instance_exec do
17
- def promise_run(**props_hash)
18
- self.new(**props_hash).promise_run
19
- end
20
- end
21
- end
22
-
23
- attr_reader :props
24
- attr_accessor :step_result
25
-
26
- def initialize(**props_hash)
27
- props_hash = self.class.validated_props(props_hash)
28
- @props = LucidProps.new(props_hash)
29
- end
30
-
31
- def current_user
32
- Isomorfeus.current_user
33
- end
34
- end
35
- end
@@ -1,10 +0,0 @@
1
- module LucidOperation
2
- class Base
3
- def self.inherited(base)
4
- base.include LucidOperation::Mixin
5
- if RUBY_ENGINE != 'opal'
6
- Isomorfeus.add_valid_operation_class(base)
7
- end
8
- end
9
- end
10
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module LucidOperation
4
- module Mixin
5
- def self.included(base)
6
- base.extend(LucidPropDeclaration::Mixin)
7
- base.extend(LucidOperation::Steps)
8
- base.extend(Isomorfeus::Operation::GenericClassApi)
9
-
10
- if RUBY_ENGINE == 'opal'
11
- def procedure(gherkin_text)
12
- end
13
-
14
- def steps
15
- end
16
- alias :gherkin :steps
17
- alias :ensure_steps :steps
18
- alias :failure_steps :steps
19
- alias :Given :steps
20
- alias :And :steps
21
- alias :Then :steps
22
- alias :When :steps
23
- alias :Ensure :steps
24
- alias :Failed :steps
25
- alias :If_failing :steps
26
- alias :When_failing :steps
27
- alias :If_this_failed :steps
28
- alias :If_that_failed :steps
29
-
30
- def First(regular_expression, &block)
31
- Isomorfeus.raise_error(message: "#{self}: First already defined, can only be defined once!") if @first_defined
32
- @first_defined = true
33
- end
34
-
35
- def Finally(regular_expression, &block)
36
- Isomorfeus.raise_error(message: "#{self}: Finally already defined, can only be defined once!") if @finally_defined
37
- @finally_defined = true
38
- end
39
- else
40
- Isomorfeus.add_valid_operation_class(base) unless base == LucidOperation::Base
41
- base.include(LucidOperation::PromiseRun)
42
-
43
- attr_reader :props
44
- attr_accessor :step_result
45
-
46
- def initialize(**props_hash)
47
- props_hash = self.class.validated_props(props_hash)
48
- @props = LucidProps.new(props_hash)
49
- end
50
-
51
- def current_user
52
- Isomorfeus.current_user
53
- end
54
-
55
- def pub_sub_client
56
- Isomorfeus.pub_sub_client
57
- end
58
- end
59
- end
60
- end
61
- end
@@ -1,10 +0,0 @@
1
- module LucidSimpleOperation
2
- class Base
3
- def self.inherited(base)
4
- base.include LucidSimpleOperation::Mixin
5
- if RUBY_ENGINE != 'opal'
6
- Isomorfeus.add_valid_operation_class(base)
7
- end
8
- end
9
- end
10
- end
@@ -1,50 +0,0 @@
1
- module LucidSimpleOperation
2
- module Mixin
3
- def self.included(base)
4
- base.extend(LucidPropDeclaration::Mixin)
5
- base.extend(Isomorfeus::Operation::GenericClassApi)
6
-
7
- if RUBY_ENGINE == 'opal'
8
- base.instance_exec do
9
- def op
10
- end
11
- end
12
- else
13
- Isomorfeus.add_valid_operation_class(base) unless base == LucidSimpleOperation::Base
14
-
15
- base.instance_exec do
16
- def op(&block)
17
- @op = block
18
- end
19
- end
20
- end
21
- end
22
-
23
- attr_reader :props
24
-
25
- def initialize(**props_hash)
26
- props_hash = self.class.validated_props(props_hash)
27
- @props = LucidProps.new(props_hash)
28
- end
29
-
30
- def promise_run
31
- original_promise = Promise.new
32
-
33
- operation = self
34
- promise = original_promise.then do |_|
35
- operation.instance_exec(&operation.class.instance_variable_get(:@op))
36
- end
37
-
38
- original_promise.resolve
39
- promise
40
- end
41
-
42
- def current_user
43
- Isomorfeus.current_user
44
- end
45
-
46
- def pub_sub_client
47
- Isomorfeus.pub_sub_client
48
- end
49
- end
50
- end