bas 1.7.2 → 1.8.0

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: a27720481a463c1a4a6edaeda8d9c159d009a11546802f559fd4232be721a146
4
+ data.tar.gz: fb829e6b146c295403118870324641d6e8e57ca3231259493aa686c4045d2b80
5
5
  SHA512:
6
- metadata.gz: e2fa969db931a22fa52e973ff7438e68f3cace2a25dd625394230c13b2939f0aa0190f3068ce69a16346bc9d7cc53aa52c7fde54f9cf76c97801f37f9c4b20c3
7
- data.tar.gz: bd4443f7a5ce9c638936cbb73062148bf77c7fe1721eba3470f602d6cfcbb5b7d0c6dca815e3e79425875a921224cfc0fee5ebf16922fe50426524273d354195
6
+ metadata.gz: 8a76d3b14aaf04f243a26968e79726025156d491f47ecde2435b5f83c316d3275a61f5cda1de54105459e0d420678c5379194d59f7c7e3d21c8208c10305c730
7
+ data.tar.gz: 34d41b30c0b3520edd259d325973b6b6a87467f7aac874ee17b630a292b68c57155c40157748a8a5c37c593e93be68dd9cee94136b55155d30324a6744a3d2db
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ # 1.8.0 (07.07.2025)
4
+ - [Feat: Implement client to interact with Operaton's API-REST](https://github.com/kommitters/bas/pull/142)
5
+
3
6
  # 1.7.2 (04.07.2025)
4
7
  - [Improve Elasticsearch mapping creation](https://github.com/kommitters/bas/pull/140)
5
8
  - [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,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "json"
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
34
+
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
42
+
43
+ def complete(task_id, variables = {})
44
+ post("/external-task/#{task_id}/complete", workerId: @worker_id,
45
+ variables: format_variables(variables))
46
+ end
47
+
48
+ def get_variables(task_id)
49
+ get("/external-task/#{task_id}/variables")
50
+ end
51
+
52
+ def unlock(task_id)
53
+ post("/external-task/#{task_id}/unlock")
54
+ end
55
+
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
64
+
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
77
+
78
+ def full_url(path)
79
+ "#{@base_url}#{path}"
80
+ end
81
+
82
+ def post(path, body = {})
83
+ handle_response(@conn.post(full_url(path), body))
84
+ end
85
+
86
+ def get(path, params = {})
87
+ handle_response(@conn.get(full_url(path), params))
88
+ end
89
+
90
+ def handle_response(response)
91
+ raise "Operaton API Error #{response.status}: #{response.body}" unless response.success?
92
+
93
+ response.body
94
+ end
95
+
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
103
+ end
104
+
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
113
+ end
114
+ end
115
+ end
116
+ end
117
+ 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.0"
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.0
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