bas 1.8.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a27720481a463c1a4a6edaeda8d9c159d009a11546802f559fd4232be721a146
4
- data.tar.gz: fb829e6b146c295403118870324641d6e8e57ca3231259493aa686c4045d2b80
3
+ metadata.gz: 83923ab43148fb334e5809f95b2c4387b6bffccb36a7b034f9f6067ad9a75783
4
+ data.tar.gz: 6d78bf8adf6e1644c85fc77c6ff3b60f21953fac861aa1dfc99210422dc84dba
5
5
  SHA512:
6
- metadata.gz: 8a76d3b14aaf04f243a26968e79726025156d491f47ecde2435b5f83c316d3275a61f5cda1de54105459e0d420678c5379194d59f7c7e3d21c8208c10305c730
7
- data.tar.gz: 34d41b30c0b3520edd259d325973b6b6a87467f7aac874ee17b630a292b68c57155c40157748a8a5c37c593e93be68dd9cee94136b55155d30324a6744a3d2db
6
+ metadata.gz: 792b8feddf38fd47f80d1b3443e4a019e2e0fdae196aa02fe6c5949492ffc586abec3a64ba4fcedd0cd53994da2bdaff81008a0d9ffe0c356e7d68650f83b84f
7
+ data.tar.gz: 73b45576f90b0d47448d78fec58f80ceca36304aa1b52e9c72813c7f102a0cdee71b80d0e1528e8d7f135af618ab2732d48e6e833746b7a46d2824d7a75a8265
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ # 1.8.1 (08.07.2025)
4
+ - [refactor: Refactor client for correct use of shared_storage](https://github.com/kommitters/bas/pull/144)
5
+
3
6
  # 1.8.0 (07.07.2025)
4
7
  - [Feat: Implement client to interact with Operaton's API-REST](https://github.com/kommitters/bas/pull/142)
5
8
 
@@ -3,113 +3,127 @@
3
3
  require "faraday"
4
4
  require "json"
5
5
 
6
- module Bas
7
- module Utils
8
- module Operaton
9
- # Client for interacting with Operaton's External Task API
10
- #
11
- # This client provides methods to manage external task lifecycle including:
12
- # - Fetching and locking tasks
13
- # - Completing tasks with variables
14
- # - Unlocking tasks
15
- # - Reporting task failures
16
- #
17
- # @example
18
- # client = ExternalTaskClient.new(base_url: "https://api.operaton.com", worker_id: "worker-123")
19
- # tasks = client.fetch_and_lock("my-topic")
20
- class ExternalTaskClient
21
- def initialize(base_url:, worker_id:)
22
- raise ArgumentError, "base_url cannot be nil or empty" if base_url.nil? || base_url.empty?
23
- raise ArgumentError, "worker_id cannot be nil or empty" if worker_id.nil? || worker_id.empty?
24
-
25
- @base_url = base_url
26
- @worker_id = worker_id
27
-
28
- @conn = Faraday.new(url: base_url) do |f|
29
- f.request :json
30
- f.response :json, content_type: /\bjson$/
31
- f.adapter Faraday.default_adapter
32
- end
33
- end
6
+ module Utils
7
+ module Operaton
8
+ # Client for interacting with Operaton's External Task API
9
+ #
10
+ # This client provides methods to manage external task lifecycle including:
11
+ # - Fetching and locking tasks
12
+ # - Completing tasks with variables
13
+ # - Unlocking tasks
14
+ # - Reporting task failures
15
+ #
16
+ # @example
17
+ # client = Utils::Operaton::ExternalTaskClient.execute(base_url: "https://api.operaton.com",
18
+ # worker_id: "worker-123")
19
+ # tasks = client.fetch_and_lock("my-topic")
20
+ class ExternalTaskClient
21
+ def self.execute(params)
22
+ new(params)
23
+ end
34
24
 
35
- def fetch_and_lock(topics_str, lock_duration: 10_000, max_tasks: 1, use_priority: true, variables: [])
36
- post("/external-task/fetchAndLock",
37
- workerId: @worker_id,
38
- maxTasks: max_tasks,
39
- usePriority: use_priority,
40
- topics: build_topics_payload(topics_str, lock_duration, variables))
41
- end
25
+ def initialize(params)
26
+ validate_params!(params)
42
27
 
43
- def complete(task_id, variables = {})
44
- post("/external-task/#{task_id}/complete", workerId: @worker_id,
45
- variables: format_variables(variables))
46
- end
28
+ @base_url = params[:base_url]
29
+ @worker_id = params[:worker_id]
47
30
 
48
- def get_variables(task_id)
49
- get("/external-task/#{task_id}/variables")
31
+ @conn = Faraday.new(url: @base_url) do |f|
32
+ f.request :json
33
+ f.response :json, content_type: /\bjson$/
34
+ f.adapter Faraday.default_adapter
50
35
  end
36
+ end
51
37
 
52
- def unlock(task_id)
53
- post("/external-task/#{task_id}/unlock")
54
- end
38
+ def fetch_and_lock(topics_str, lock_duration: 10_000, max_tasks: 1, use_priority: true, variables: [])
39
+ post(
40
+ "/external-task/fetchAndLock",
41
+ workerId: @worker_id,
42
+ maxTasks: max_tasks,
43
+ usePriority: use_priority,
44
+ topics: build_topics_payload(topics_str, lock_duration, variables)
45
+ )
46
+ end
55
47
 
56
- def report_failure(task_id, error_message:, error_details:, retries:, retry_timeout:)
57
- post("/external-task/#{task_id}/failure",
58
- workerId: @worker_id,
59
- errorMessage: error_message,
60
- errorDetails: error_details,
61
- retries: retries,
62
- retryTimeout: retry_timeout)
63
- end
48
+ def complete(task_id, variables = {})
49
+ post(
50
+ "/external-task/#{task_id}/complete",
51
+ workerId: @worker_id,
52
+ variables: format_variables(variables)
53
+ )
54
+ end
64
55
 
65
- private
66
-
67
- def build_topics_payload(topics_str, lock_duration, variables)
68
- topic_names = topics_str.is_a?(Array) ? topics_str : topics_str.to_s.split(",")
69
- topic_names.map do |name|
70
- {
71
- topicName: name.strip,
72
- lockDuration: lock_duration,
73
- variables: variables
74
- }
75
- end
76
- end
56
+ def get_variables(task_id)
57
+ get("/external-task/#{task_id}/variables")
58
+ end
77
59
 
78
- def full_url(path)
79
- "#{@base_url}#{path}"
80
- end
60
+ def unlock(task_id)
61
+ post("/external-task/#{task_id}/unlock")
62
+ end
81
63
 
82
- def post(path, body = {})
83
- handle_response(@conn.post(full_url(path), body))
84
- end
64
+ def report_failure(task_id, error_message:, error_details:, retries:, retry_timeout:)
65
+ post(
66
+ "/external-task/#{task_id}/failure",
67
+ workerId: @worker_id,
68
+ errorMessage: error_message,
69
+ errorDetails: error_details,
70
+ retries: retries,
71
+ retryTimeout: retry_timeout
72
+ )
73
+ end
85
74
 
86
- def get(path, params = {})
87
- handle_response(@conn.get(full_url(path), params))
88
- end
75
+ private
89
76
 
90
- def handle_response(response)
91
- raise "Operaton API Error #{response.status}: #{response.body}" unless response.success?
77
+ def validate_params!(params)
78
+ raise ArgumentError, "base_url cannot be nil or empty" if params[:base_url].to_s.strip.empty?
79
+ raise ArgumentError, "worker_id cannot be nil or empty" if params[:worker_id].to_s.strip.empty?
80
+ end
92
81
 
93
- response.body
82
+ def build_topics_payload(topics_str, lock_duration, variables)
83
+ topic_names = topics_str.is_a?(Array) ? topics_str : topics_str.to_s.split(",")
84
+ topic_names.map do |name|
85
+ {
86
+ topicName: name.strip,
87
+ lockDuration: lock_duration,
88
+ variables: variables
89
+ }
94
90
  end
91
+ end
92
+
93
+ def full_url(path)
94
+ "#{@base_url}#{path}"
95
+ end
96
+
97
+ def post(path, body = {})
98
+ handle_response(@conn.post(full_url(path), body))
99
+ end
100
+
101
+ def get(path, params = {})
102
+ handle_response(@conn.get(full_url(path), params))
103
+ end
104
+
105
+ def handle_response(response)
106
+ raise "Operaton API Error #{response.status}: #{response.body}" unless response.success?
95
107
 
96
- def format_variables(vars)
97
- vars.transform_values do |value|
98
- {
99
- value: value,
100
- type: ruby_type_to_operaton_type(value)
101
- }
102
- end
108
+ response.body
109
+ end
110
+
111
+ def format_variables(vars)
112
+ vars.transform_values do |value|
113
+ {
114
+ value: value,
115
+ type: ruby_type_to_operaton_type(value)
116
+ }
103
117
  end
118
+ end
104
119
 
105
- def ruby_type_to_operaton_type(value)
106
- case value
107
- when String then "String"
108
- when Integer then "Integer"
109
- when Float then "Double"
110
- when TrueClass, FalseClass then "Boolean"
111
- else "Object"
112
- end
120
+ def ruby_type_to_operaton_type(value)
121
+ case value
122
+ when String then "String"
123
+ when Integer then "Integer"
124
+ when Float then "Double"
125
+ when TrueClass, FalseClass then "Boolean"
126
+ else "Object"
113
127
  end
114
128
  end
115
129
  end
data/lib/bas/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Bas
4
4
  # Gem version
5
- VERSION = "1.8.0"
5
+ VERSION = "1.8.1"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bas
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kommitters Open Source