bas 1.7.2 → 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: 87acac8ff5c199705abe5b3e41d72834bf104298aa2533740dd40a637f7d7ca2
4
- data.tar.gz: d8bc727403b7eaaf2211116fb0e697a0c7b709022b43528ac1d4afffb25c7167
3
+ metadata.gz: 83923ab43148fb334e5809f95b2c4387b6bffccb36a7b034f9f6067ad9a75783
4
+ data.tar.gz: 6d78bf8adf6e1644c85fc77c6ff3b60f21953fac861aa1dfc99210422dc84dba
5
5
  SHA512:
6
- metadata.gz: e2fa969db931a22fa52e973ff7438e68f3cace2a25dd625394230c13b2939f0aa0190f3068ce69a16346bc9d7cc53aa52c7fde54f9cf76c97801f37f9c4b20c3
7
- data.tar.gz: bd4443f7a5ce9c638936cbb73062148bf77c7fe1721eba3470f602d6cfcbb5b7d0c6dca815e3e79425875a921224cfc0fee5ebf16922fe50426524273d354195
6
+ metadata.gz: 792b8feddf38fd47f80d1b3443e4a019e2e0fdae196aa02fe6c5949492ffc586abec3a64ba4fcedd0cd53994da2bdaff81008a0d9ffe0c356e7d68650f83b84f
7
+ data.tar.gz: 73b45576f90b0d47448d78fec58f80ceca36304aa1b52e9c72813c7f102a0cdee71b80d0e1528e8d7f135af618ab2732d48e6e833746b7a46d2824d7a75a8265
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
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
+
6
+ # 1.8.0 (07.07.2025)
7
+ - [Feat: Implement client to interact with Operaton's API-REST](https://github.com/kommitters/bas/pull/142)
8
+
3
9
  # 1.7.2 (04.07.2025)
4
10
  - [Improve Elasticsearch mapping creation](https://github.com/kommitters/bas/pull/140)
5
11
  - [Fix in Elasticsearch shared storage update_stage method](https://github.com/kommitters/bas/pull/139)
data/Gemfile CHANGED
@@ -15,6 +15,10 @@ gem "simplecov-lcov", "~> 0.8.0"
15
15
  gem "vcr"
16
16
  gem "webmock"
17
17
 
18
+ gem "faraday", "~> 2.9"
19
+
20
+ gem "json", "~> 2.8"
21
+
18
22
  gem "elasticsearch", "~> 8.0"
19
23
  gem "httparty"
20
24
  gem "pg", "~> 1.5", ">= 1.5.4"
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "json"
5
+
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
24
+
25
+ def initialize(params)
26
+ validate_params!(params)
27
+
28
+ @base_url = params[:base_url]
29
+ @worker_id = params[:worker_id]
30
+
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
35
+ end
36
+ end
37
+
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
47
+
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
55
+
56
+ def get_variables(task_id)
57
+ get("/external-task/#{task_id}/variables")
58
+ end
59
+
60
+ def unlock(task_id)
61
+ post("/external-task/#{task_id}/unlock")
62
+ end
63
+
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
74
+
75
+ private
76
+
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
81
+
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
+ }
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?
107
+
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
+ }
117
+ end
118
+ end
119
+
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"
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
data/lib/bas/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Bas
4
4
  # Gem version
5
- VERSION = "1.7.2"
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.7.2
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kommitters Open Source
@@ -98,6 +98,7 @@ files:
98
98
  - lib/bas/utils/notion/update_db_page.rb
99
99
  - lib/bas/utils/notion/update_db_state.rb
100
100
  - lib/bas/utils/openai/run_assistant.rb
101
+ - lib/bas/utils/operaton/external_task_client.rb
101
102
  - lib/bas/utils/postgres/request.rb
102
103
  - lib/bas/version.rb
103
104
  - renovate.json