workmesh 1.0.5 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/workmesh.rb +32 -39
  3. metadata +22 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4e93016a2c4975149768794a4084eb3fb2b86af9752278ff780044d6ade7707
4
- data.tar.gz: 81a01ab4e3d12ccab133853f6acd1233b300be0bfed817f74f53bc258224c86c
3
+ metadata.gz: 440c98bcca1d0df1215bae66c24f01caaf14921a51f31a1765f8f9779d9525c8
4
+ data.tar.gz: 42824bd2a9f6e6d9849956987f00e2987949a735bb3c4e4971a47ebe35c0124b
5
5
  SHA512:
6
- metadata.gz: cd19ed6730ccee45fd47eec84326b34ca506610ebf3cbabadf8cc5da8acc2a15baac5665140122116233c8d0569943983a2be495677e345789fe98407987d3f7
7
- data.tar.gz: b1868444351445b73e1fbe87397873e40a545cb3bd1be2f697cfc9d719fde1800902cd37a63c332f0d05dc00c962e2bbc513d57c4949f6703c69bd5eed5a4f9c
6
+ metadata.gz: 8ac434b798d8e2ce317136bd3af1146279a2215317087deef184d0933eb6c1895f7415c069f96bf515ae7caa7164f30bb9ff7be99803f74478237c3979b833c9
7
+ data.tar.gz: a45ecb1a637b90a358e139702c97d6816b20c93a08edb28e1c7c4db90638644188427b58d90e5228e56d2a6e03bab99a98fcae6f1518efe7228482c6eb68f816
data/lib/workmesh.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'colorize'
2
2
  require 'sequel'
3
+ require 'blackstack-db'
3
4
  require 'blackstack-core'
4
5
  require 'blackstack-nodes'
5
6
  require 'simple_command_line_parser'
@@ -8,27 +9,6 @@ require 'simple_cloud_logging'
8
9
  require_relative '../deployment-routines/update-config'
9
10
  require_relative '../deployment-routines/update-source'
10
11
 
11
- =begin
12
- # TODO: Move this to a gem with the CRDB module
13
- #
14
- # return a postgresql uuid
15
- #
16
- def guid()
17
- DB['SELECT gen_random_uuid() AS id'].first[:id]
18
- end
19
- =end
20
-
21
- # TODO: Move new() to a gem with the CRDB module
22
- #
23
- # return current datetime with format `%Y-%m-%d %H:%M:%S %Z`, using the timezone of the database (`select current_setting('TIMEZONE')`)
24
- # TODO: I am hardcoding the value of `tz` because for any reason `SELECT current_setting('TIMEZONE')` returns `UTC` instead of
25
- # `America/Argentina/Buenos_Aires` when I run it from Ruby. Be sure your database is ALWAYS configured with the correct timezone.
26
- #
27
- def now()
28
- tz = 'America/Argentina/Buenos_Aires' #DB["SELECT current_setting('TIMEZONE') AS tz"].first[:tz]
29
- DB["SELECT current_timestamp() at TIME ZONE '#{tz}' AS now"].first[:now]
30
- end
31
-
32
12
  module BlackStack
33
13
  module Workmesh
34
14
  # stub node class
@@ -82,7 +62,7 @@ module BlackStack
82
62
  attr_accessor :entity_table, :entity_field_id, :entity_field_sort
83
63
  attr_accessor :push_function, :entity_field_push_time, :entity_field_push_success, :entity_field_push_error_description
84
64
  attr_accessor :pull_status_access_point
85
- attr_accessor :pull_function, :enttity_field_pull_time, :entity_field_pull_success, :entity_field_pull_error_description
65
+ attr_accessor :pull_function #, :enttity_field_pull_time, :entity_field_pull_success, :entity_field_pull_error_description
86
66
 
87
67
  def self.descriptor_errors(h)
88
68
  errors = []
@@ -109,14 +89,14 @@ module BlackStack
109
89
  errors << "The key :entity_field_push_error_description is missing" if h[:push_function] && h[:entity_field_push_error_description].nil?
110
90
 
111
91
  # valiudate: if :pull_function exists, the key :pull_status_access_point exists and it is a string
112
- errors << "The key :pull_status_access_point is missing" if h[:pull_function] && h[:pull_status_access_point].nil?
113
- errors << "The key :pull_status_access_point must be an String" unless h[:pull_function].nil? || h[:pull_status_access_point].is_a?(String)
92
+ #errors << "The key :pull_status_access_point is missing" if h[:pull_function] && h[:pull_status_access_point].nil?
93
+ #errors << "The key :pull_status_access_point must be an String" unless h[:pull_function].nil? || h[:pull_status_access_point].is_a?(String)
114
94
  # validate: if :pull_function exists, the key :entity_field_pull_time exists and it is a symbol
115
- errors << "The key :entity_field_pull_time is missing" if h[:pull_function] && h[:entity_field_pull_time].nil?
95
+ #errors << "The key :entity_field_pull_time is missing" if h[:pull_function] && h[:entity_field_pull_time].nil?
116
96
  # validate: if :pull_function exists, the key :entity_field_pull_success exists and it is a symbol
117
- errors << "The key :entity_field_pull_success is missing" if h[:pull_function] && h[:entity_field_pull_success].nil?
97
+ #errors << "The key :entity_field_pull_success is missing" if h[:pull_function] && h[:entity_field_pull_success].nil?
118
98
  # validate: if :pull_function exists, the key :entity_field_pull_error_description exists and it is a symbol
119
- errors << "The key :entity_field_pull_error_description is missing" if h[:pull_function] && h[:entity_field_pull_error_description].nil?
99
+ #errors << "The key :entity_field_pull_error_description is missing" if h[:pull_function] && h[:entity_field_pull_error_description].nil?
120
100
 
121
101
  # return list of errors
122
102
  errors.uniq
@@ -134,9 +114,9 @@ module BlackStack
134
114
  self.entity_field_push_success = h[:entity_field_push_success]
135
115
  self.entity_field_push_error_description = h[:entity_field_push_error_description]
136
116
  self.pull_function = h[:pull_function]
137
- self.enttity_field_pull_time = h[:entity_field_pull_time]
138
- self.entity_field_pull_success = h[:entity_field_pull_success]
139
- self.entity_field_pull_error_description = h[:entity_field_pull_error_description]
117
+ #self.enttity_field_pull_time = h[:entity_field_pull_time]
118
+ #self.entity_field_pull_success = h[:entity_field_pull_success]
119
+ #self.entity_field_pull_error_description = h[:entity_field_pull_error_description]
140
120
  end
141
121
 
142
122
  def to_hash()
@@ -150,18 +130,19 @@ module BlackStack
150
130
  ret[:entity_field_push_success] = self.entity_field_push_success
151
131
  ret[:entity_field_push_error_description] = self.entity_field_push_error_description
152
132
  ret[:pull_function] = self.pull_function
153
- ret[:enttity_field_pull_time] = self.enttity_field_pull_time
154
- ret[:entity_field_pull_success] = self.entity_field_pull_success
155
- ret[:entity_field_pull_error_description] = self.entity_field_pull_error_description
133
+ #ret[:enttity_field_pull_time] = self.enttity_field_pull_time
134
+ #ret[:entity_field_pull_success] = self.entity_field_pull_success
135
+ #ret[:entity_field_pull_error_description] = self.entity_field_pull_error_description
156
136
  ret
157
137
  end
158
138
 
159
139
  # execute the push function of this protocol, and update the push flags
160
- def push(entity, node)
140
+ def push(entity, node, l=nil)
141
+ l = BlackStack::DummyLogger.new(nil) if l.nil?
161
142
  raise 'The push function is not defined' if self.push_function.nil?
162
143
  entity[entity_field_push_time] = now()
163
144
  begin
164
- self.push_function.call(entity, node)
145
+ self.push_function.call(entity, node, l)
165
146
  entity[entity_field_push_success] = true
166
147
  entity[entity_field_push_error_description] = nil
167
148
  entity.save
@@ -171,7 +152,19 @@ module BlackStack
171
152
  entity.save
172
153
  raise e
173
154
  end
174
- end
155
+ end # def push(entity, node, l=nil)
156
+
157
+ # execute the pull function of this protocol, and update the push flags
158
+ def pull(node, l=nil)
159
+ l = BlackStack::DummyLogger.new(nil) if l.nil?
160
+ raise 'The pull function is not defined' if self.pull_function.nil?
161
+ begin
162
+ self.pull_function.call(node, l)
163
+ rescue => e
164
+ raise e
165
+ end
166
+ end # def pull(node, l=nil)
167
+
175
168
  end # class Protocol
176
169
 
177
170
  # stub worker class
@@ -196,8 +189,8 @@ module BlackStack
196
189
  if h[:protocols].is_a?(Array)
197
190
  h[:protocols].each do |protocol|
198
191
  errors << "The key :protocols must be an Array of valid hash descritors of the Protocol class" unless protocol.is_a?(Hash)
199
- protocol_errors = Protocol.descriptor_errors(protocol)
200
- errors << "The key :protocols must be an Array of valid hash descritors of the Protocol class. Errors found are: #{protocol_errors.join('. ')}" unless protocol_errors.length == 0
192
+ z = Protocol.descriptor_errors(protocol)
193
+ errors << "The key :protocols must be an Array of valid hash descritors of the Protocol class (errors: #{z.join('. ')})" unless z.length == 0
201
194
  end
202
195
  end
203
196
  # validate: the key :assignation is nil or it is a symbol belonging the array ASSIGANTIONS
@@ -211,7 +204,7 @@ module BlackStack
211
204
  # setup dispatcher configuration here
212
205
  def initialize(h)
213
206
  errors = BlackStack::Workmesh::Service.descriptor_errors(h)
214
- raise "The worker descriptor is not valid: #{errors.uniq.join(".\n")}" if errors.length > 0
207
+ raise "The service descriptor is not valid: #{errors.uniq.join(".\n")}" if errors.length > 0
215
208
  self.name = h[:name]
216
209
  self.entity_table = h[:entity_table]
217
210
  self.entity_field_assignation = h[:entity_field_assignation]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workmesh
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Daniel Sardi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-18 00:00:00.000000000 Z
11
+ date: 2024-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -30,6 +30,26 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 5.56.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: blackstack-db
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 1.0.6
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.0.6
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 1.0.6
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.0.6
33
53
  - !ruby/object:Gem::Dependency
34
54
  name: blackstack-core
35
55
  requirement: !ruby/object:Gem::Requirement