pampa 2.0.15 → 2.0.17

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pampa.rb +21 -40
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8627e0b3e3f9d923c9dc750fde056078bfd202a74e3abd36eecfa27566c93f3
4
- data.tar.gz: 27990d2b64539c229974280e5d80b630b7e6dfb05b4b6533ef8976031e791a7d
3
+ metadata.gz: fbbd19e65301b23d9e1ce78458528c5bdeecb73f2d54047e2546df8ad54f229d
4
+ data.tar.gz: aaea0b4f3b174b565cec083ff833c52b255aede1304757a2383f23057ea25f06
5
5
  SHA512:
6
- metadata.gz: 71fb9a3ab3965c5aa591412c358ff6074b12d9e7ff6b8409d941ac28e42ba2ccb85288f1987a20758fd81c795d22323c597c2f15be040d5e1b628fed008aaecb
7
- data.tar.gz: e33cfc7bca76c0a3031c4bfdc96417cfba6fadbcf7593b499a9eb2b5cefd996371b05548f159149ff2d204ae8035c524ac77c2dadbb081bde93693f0e64da1d9
6
+ metadata.gz: 26472faf3ef44736e06ea39351fcc4380c7ba94f282051df49f12d2572190daca659603866f6a4275dc793b1408c992fa20310500ae74d28f283d6d75eac97ee
7
+ data.tar.gz: 7893ba252991c1e5603b00372d5a719552a3134fdd1daed6ed168c28c9f6864ed8d36561fe531f8ffef11557c099f9340c14b8411177b96f6714e10c9f498250
data/lib/pampa.rb CHANGED
@@ -23,6 +23,11 @@ module BlackStack
23
23
  # Connection string to the database. Example: mysql2://user:password@localhost:3306/database
24
24
  @@connection_string = nil
25
25
 
26
+ def self.now()
27
+ tz = 'America/Argentina/Buenos_Aires' #DB["SELECT current_setting('TIMEZONE') AS tz"].first[:tz]
28
+ DB["SELECT current_timestamp() at TIME ZONE '#{tz}' AS now"].first[:now]
29
+ end
30
+
26
31
  # @@integrate_with_blackstack_deployer
27
32
  def self.integrate_with_blackstack_deployer()
28
33
  @@integrate_with_blackstack_deployer
@@ -138,34 +143,6 @@ module BlackStack
138
143
  @@jobs
139
144
  end
140
145
 
141
- =begin
142
- # return a hash descriptor of the whole configuration of the cluster.
143
- def self.to_hash()
144
- ret = {
145
- :log_filename => self.log_filename,
146
- :connection_string => self.connection_string,
147
- }
148
- #ret[:workers] = []
149
- #@@workers.each do |w|
150
- # ret[:workers] << w.to_hash
151
- #end
152
- ret[:nodes] = []
153
- @@nodes.each do |n|
154
- ret[:nodes] << n.to_hash
155
- end
156
- ret[:jobs] = []
157
- @@jobs.each do |j|
158
- ret[:jobs] << j.to_hash
159
- end
160
- ret
161
- end # def self.to_hash()
162
-
163
- # setup from a whole hash descriptor
164
- def self.initialize(h)
165
- # TODO
166
- end
167
- =end
168
-
169
146
  # get attached and unassigned workers.
170
147
  # assign and unassign workers to jobs.
171
148
  #
@@ -199,6 +176,7 @@ module BlackStack
199
176
  l.logf("done (#{assigned.size.to_s})")
200
177
 
201
178
  l.logs("Getting total pending tasks... ")
179
+
202
180
  pendings = job.selecting(job.max_pending_tasks)
203
181
  l.logf("done (#{pendings.size.to_s})")
204
182
 
@@ -804,14 +782,11 @@ module BlackStack
804
782
 
805
783
  # returns an array of failed tasks for restarting.
806
784
  def relaunching_dataset(n)
807
- #ds = DB[self.table.to_sym].where("#{self.field_time.to_s} < CURRENT_TIMESTAMP() - INTERVAL '#{self.max_job_duration_minutes.to_i} minutes'")
808
- #ds = ds.filter("#{self.field_end_time.to_s} IS NULL") if !self.field_end_time.nil?
809
- #ds.limit(n).all
810
785
  q = "
811
786
  SELECT *
812
787
  FROM #{self.table.to_s}
813
788
  WHERE #{self.field_time.to_s} IS NOT NULL
814
- AND #{self.field_time.to_s} < CURRENT_TIMESTAMP() - INTERVAL '#{self.max_job_duration_minutes.to_i} minutes'
789
+ AND #{self.field_time.to_s} < CAST('#{BlackStack::Pampa.now}' AS TIMESTAMP) - INTERVAL '#{self.max_job_duration_minutes.to_i} minutes'
815
790
  AND #{self.field_id.to_s} IS NOT NULL
816
791
  AND #{self.field_end_time.to_s} IS NULL
817
792
  AND COALESCE(#{self.field_times.to_s},0) < #{self.max_try_times.to_i}
@@ -830,19 +805,25 @@ module BlackStack
830
805
  end
831
806
  end
832
807
 
808
+ def update(o)
809
+ DB[self.table.to_sym].where(
810
+ self.field_primary_key.to_sym => o[self.field_primary_key.to_sym]
811
+ ).update(o)
812
+ end
813
+
833
814
  def relaunch(o)
834
815
  o[self.field_id.to_sym] = nil
835
816
  o[self.field_time.to_sym] = nil
836
817
  o[self.field_start_time.to_sym] = nil if !self.field_start_time.nil?
837
818
  o[self.field_end_time.to_sym] = nil if !self.field_end_time.nil?
838
- DB[self.table.to_sym].where(self.field_primary_key.to_sym => o[self.field_primary_key.to_sym]).update(o)
819
+ self.update(o)
839
820
  end
840
821
 
841
822
  def start(o)
842
823
  if self.starter_function.nil?
843
- o[self.field_start_time.to_sym] = DB["SELECT CURRENT_TIMESTAMP() AS dt"].first[:dt] if !self.field_start_time.nil? # IMPORTANT: use DB location to get current time.
824
+ o[self.field_start_time.to_sym] = DB["SELECT CAST('#{BlackStack::Pampa.now}' AS TIMESTAMP) AS dt"].first[:dt] if !self.field_start_time.nil? # IMPORTANT: use DB location to get current time.
844
825
  o[self.field_times.to_sym] = o[self.field_times.to_sym].to_i + 1
845
- DB[self.table.to_sym].where(self.field_primary_key.to_sym => o[self.field_primary_key.to_sym]).update(o)
826
+ self.update(o)
846
827
  else
847
828
  self.starter_function.call(o, self)
848
829
  end
@@ -850,10 +831,10 @@ module BlackStack
850
831
 
851
832
  def finish(o, e=nil)
852
833
  if self.finisher_function.nil?
853
- o[self.field_end_time.to_sym] = DB["SELECT CURRENT_TIMESTAMP() AS dt"].first[:dt] if !self.field_end_time.nil? && e.nil? # IMPORTANT: use DB location to get current time.
834
+ o[self.field_end_time.to_sym] = DB["SELECT CAST('#{BlackStack::Pampa.now}' AS TIMESTAMP) AS dt"].first[:dt] if !self.field_end_time.nil? && e.nil? # IMPORTANT: use DB location to get current time.
854
835
  o[self.field_success.to_sym] = e.nil?
855
836
  o[self.field_error_description.to_sym] = e.to_console if !e.nil?
856
- DB[self.table.to_sym].where(self.field_primary_key.to_sym => o[self.field_primary_key.to_sym]).update(o)
837
+ self.update(o)
857
838
  else
858
839
  self.finisher_function.call(o, e, self)
859
840
  end
@@ -886,12 +867,12 @@ module BlackStack
886
867
  self.selecting(n).each { |o|
887
868
  # count the # of dispatched
888
869
  i += 1
889
- # dispatch records
870
+ # dispatch
890
871
  o[self.field_id.to_sym] = worker.id
891
- o[self.field_time.to_sym] = DB["SELECT CURRENT_TIMESTAMP() AS dt"].first[:dt] # IMPORTANT: use DB location to get current time.
872
+ o[self.field_time.to_sym] = DB["SELECT CAST('#{BlackStack::Pampa.now}' AS TIMESTAMP) AS dt"].first[:dt] # IMPORTANT: use DB location to get current time.
892
873
  o[self.field_start_time.to_sym] = nil if !self.field_start_time.nil?
893
874
  o[self.field_end_time.to_sym] = nil if !self.field_end_time.nil?
894
- DB[self.table.to_sym].where(self.field_primary_key.to_sym => o[self.field_primary_key.to_sym]).update(o)
875
+ self.update(o)
895
876
  # release resources
896
877
  DB.disconnect
897
878
  GC.start
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pampa
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.15
4
+ version: 2.0.17
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: 2022-12-12 00:00:00.000000000 Z
11
+ date: 2022-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel