pampa 2.0.27 → 2.0.29

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/pampa.rb +124 -53
  3. metadata +2 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 766a4c8e58dcd60e3938ae32600b3715f696418c7f4f2d4cb15ea22fa8559213
4
- data.tar.gz: 2a131d44bba1996839e5fc03a0a12148c6429d49b050a711c4bcc91a00fe34b2
3
+ metadata.gz: '095438d108ee4f3cd1cf5d329fb1a0d29c38d6647a130c811e75ed2d73105d81'
4
+ data.tar.gz: 45dd332d64c86e75d7e0b0f8e4575e3884a9cf486eabb959371af3b1da2c674c
5
5
  SHA512:
6
- metadata.gz: 3e8bc763b08173e152f9a7a6fdc3c75fa1aca6e2522cba7b919fa2b5c6f71653266fc7f2e29fbfc749a59af706bf3cb63624ef8ce4da903349ae7001c4c5aad1
7
- data.tar.gz: d03a80fcd845fe760be93a42b720528cc518fd1380cee51dc1d1ab2439254d23ed2ef6c42acf4075b9290f513151486b28c90bf7c568731516a29394a1859db9
6
+ metadata.gz: e76a96906f54dafa73f37c4109581f1779c77f086788a98e8278960bf2086228a1fd09851b3e37b94c72920495d009567d1f96699c63b87567925c84b8a1af2c
7
+ data.tar.gz: a4869784e7f39a12eb3ef8327584ab773a0a0eac2b22c997cde5dd008e34f13fcdc5e9c0b05b5db86392e3fe8ffa4f8fdd5699052c5e5781d9a9990cae0546d9
data/lib/pampa.rb CHANGED
@@ -1,14 +1,11 @@
1
1
  require 'sequel'
2
2
  require 'blackstack-core'
3
3
  require 'blackstack-nodes'
4
- require 'blackstack-deployer'
5
4
  require 'simple_command_line_parser'
6
5
  require 'simple_cloud_logging'
7
6
 
8
7
  module BlackStack
9
8
  module Pampa
10
- # activate this flag if you want to add pampa nodes to blackstack-deployer.
11
- @@integrate_with_blackstack_deployer = false
12
9
  # setup custom locations for config and worker files.
13
10
  @@config_filename = "config.rb"
14
11
  @@worker_filename = "worker.rb"
@@ -28,15 +25,6 @@ module BlackStack
28
25
  DB["SELECT current_timestamp at TIME ZONE '#{tz}' AS now"].first[:now]
29
26
  end
30
27
 
31
- # @@integrate_with_blackstack_deployer
32
- def self.integrate_with_blackstack_deployer()
33
- @@integrate_with_blackstack_deployer
34
- end
35
-
36
- def self.set_integrate_with_blackstack_deployer(b)
37
- @@integrate_with_blackstack_deployer = b
38
- end
39
-
40
28
  # @@config_filename
41
29
  def self.config_filename()
42
30
  @@config_filename
@@ -97,8 +85,6 @@ module BlackStack
97
85
  # add a node to the cluster.
98
86
  def self.add_node(h)
99
87
  @@nodes << BlackStack::Pampa::Node.new(h)
100
- # add to deployer
101
- BlackStack::Deployer.add_node(h) if @@integrate_with_blackstack_deployer
102
88
  end # def self.add_node(h)
103
89
 
104
90
  # add an array of nodes to the cluster.
@@ -177,8 +163,8 @@ module BlackStack
177
163
  assigned = BlackStack::Pampa.workers.select { |worker| worker.attached && worker.assigned_job.to_s == job.name.to_s }
178
164
  l.logf("done (#{assigned.size.to_s})")
179
165
 
180
- l.logs("Getting total pending (idle) tasks... ")
181
- pendings = job.idle
166
+ l.logs("Getting total pending (pending) tasks... ")
167
+ pendings = job.pending
182
168
  l.logf("done (#{pendings.to_s})")
183
169
 
184
170
  l.logs("0 pending tasks?.... ")
@@ -632,6 +618,9 @@ module BlackStack
632
618
  # max number of times that a record can start to process & fail (:start_time field is not nil,
633
619
  # but :end_time field is still nil after :max_job_duration_minutes)
634
620
  attr_accessor :max_try_times
621
+
622
+ # CUSTOM DISPATCHING FUNCTIONS
623
+ #
635
624
  # additional function to returns an array of tasks pending to be processed by a worker.
636
625
  # it should returns an array
637
626
  # keep it nil if you want to run the default function
@@ -661,9 +650,23 @@ module BlackStack
661
650
  attr_accessor :finisher_function
662
651
  # Function to execute for each task.
663
652
  attr_accessor :processing_function
653
+
654
+ # CUSTOM REPORTING FUNCTIONS
655
+ #
656
+ # additional function to returns the number of total tasks.
657
+ # it should returns an array
658
+ # keep it nil if you want to run the default function
659
+ attr_accessor :total_function
660
+ attr_accessor :completed_function
661
+ attr_accessor :pending_function
662
+ attr_accessor :failed_function
663
+
664
+ # ELASTIC WORKERS ASSIGNATION
665
+ #
664
666
  # stretch assignation/unassignation of workers
665
667
  attr_accessor :max_pending_tasks
666
668
  attr_accessor :max_assigned_workers
669
+
667
670
  # choose workers to assign tasks
668
671
  attr_accessor :filter_worker_id
669
672
 
@@ -683,6 +686,8 @@ module BlackStack
683
686
  :queue_size => self.queue_size,
684
687
  :max_job_duration_minutes => self.max_job_duration_minutes,
685
688
  :max_try_times => self.max_try_times,
689
+
690
+ # dispatching custom functions
686
691
  :occupied_function => self.occupied_function.to_s,
687
692
  :allowing_function => self.allowing_function.to_s,
688
693
  :selecting_function => self.selecting_function.to_s,
@@ -693,7 +698,13 @@ module BlackStack
693
698
  :processing_function => self.processing_function.to_s,
694
699
  :max_pending_tasks => self.max_pending_tasks,
695
700
  :max_assigned_workers => self.max_assigned_workers,
696
- :filter_worker_id => self.filter_worker_id
701
+ :filter_worker_id => self.filter_worker_id,
702
+
703
+ # reporting custom functions
704
+ :total_function => self.total_function.to_s,
705
+ :completed_function => self.completed_function.to_s,
706
+ :pending_function => self.pending_function.to_s,
707
+ :failed_function => self.failed_function.to_s,
697
708
  }
698
709
  end
699
710
 
@@ -721,12 +732,22 @@ module BlackStack
721
732
  self.queue_size = h[:queue_size]
722
733
  self.max_job_duration_minutes = h[:max_job_duration_minutes]
723
734
  self.max_try_times = h[:max_try_times]
735
+
736
+ # dispatching custom functions
724
737
  self.occupied_function = h[:occupied_function]
725
738
  self.allowing_function = h[:allowing_function]
726
739
  self.selecting_function = h[:selecting_function]
727
740
  self.relaunching_function = h[:relaunching_function]
728
741
  self.relauncher_function = h[:relauncher_function]
729
742
  self.processing_function = h[:processing_function]
743
+
744
+ # reporting custom functions
745
+ self.total_function = h[:total_function]
746
+ self.completed_function = h[:completed_function]
747
+ self.pending_function = h[:pending_function]
748
+ self.failed_function = h[:failed_function]
749
+
750
+ # elastic workers assignation
730
751
  self.max_pending_tasks = h[:max_pending_tasks]
731
752
  self.max_assigned_workers = h[:max_assigned_workers]
732
753
  self.filter_worker_id = h[:filter_worker_id]
@@ -914,62 +935,112 @@ module BlackStack
914
935
  return i
915
936
  end
916
937
 
917
- # reporting methods
918
- # idle + failed + completed = total
938
+ # reporting methods
939
+ #
919
940
 
920
- # reporting method: idle
921
- # reutrn the number of idle tasks.
922
- # if the numbr if idle tasks is higher than `max_tasks_to_show` then it returns `max_tasks_to_show`+.
941
+ # reporting method: total
942
+ # reutrn the number of total tasks.
943
+ # if the numbr if total tasks is higher than `max_tasks_to_show` then it returns `max_tasks_to_show`+.
923
944
  def total
924
945
  j = self
925
- q = "
926
- SELECT COUNT(*) AS n
927
- FROM #{j.table.to_s}
928
- "
929
- DB[q].first[:n].to_i
946
+ if self.total_function.nil?
947
+ q = "
948
+ SELECT COUNT(*) AS n
949
+ FROM #{j.table.to_s}
950
+ "
951
+ return DB[q].first[:n].to_i
952
+ else
953
+ return self.total_function.call
954
+ end
930
955
  end # def total
931
956
 
932
957
 
933
- # reporting method: idle
934
- # reutrn the number of idle tasks.
935
- # if the numbr if idle tasks is higher than `max_tasks_to_show` then it returns `max_tasks_to_show`+.
958
+ # reporting method: completed
959
+ # reutrn the number of completed tasks.
960
+ # if the numbr if completed tasks is higher than `max_tasks_to_show` then it returns `max_tasks_to_show`+.
936
961
  def completed
937
962
  j = self
938
- q = "
939
- SELECT COUNT(*) AS n
940
- FROM #{j.table.to_s}
941
- WHERE COALESCE(#{j.field_success.to_s},false)=true
942
- "
943
- DB[q].first[:n].to_i
963
+ if self.completed_function.nil?
964
+ q = "
965
+ SELECT COUNT(*) AS n
966
+ FROM #{j.table.to_s}
967
+ WHERE COALESCE(#{j.field_success.to_s},false)=true
968
+ "
969
+ return DB[q].first[:n].to_i
970
+ else
971
+ return self.completed_function.call
972
+ end
944
973
  end # def completed
945
974
 
946
- # reporting method: idle
947
- # reutrn the number of idle tasks.
948
- # if the numbr if idle tasks is higher than `max_tasks_to_show` then it returns `max_tasks_to_show`+.
949
- def idle
975
+ # reporting method: pending
976
+ # reutrn the number of pending tasks.
977
+ # if the numbr if pending tasks is higher than `max_tasks_to_show` then it returns `max_tasks_to_show`+.
978
+ def pending
950
979
  j = self
980
+ if self.pending_function.nil?
981
+ q = "
982
+ SELECT COUNT(*) AS n
983
+ FROM #{j.table.to_s}
984
+ WHERE COALESCE(#{j.field_success.to_s},false)=false
985
+ AND COALESCE(#{j.field_times.to_s},0) < #{j.max_try_times.to_i}
986
+ "
987
+ return DB[q].first[:n].to_i
988
+ else
989
+ return self.pending_function.call
990
+ end
991
+ end # def pending
992
+
993
+ # reporting method: running
994
+ # return the number of running tasks.
995
+ # if the number if running tasks is higher than `max_tasks_to_show` then it returns `max_tasks_to_show`+.
996
+ def failed
997
+ j = self
998
+ if self.failed_function.nil?
951
999
  q = "
952
1000
  SELECT COUNT(*) AS n
953
1001
  FROM #{j.table.to_s}
954
1002
  WHERE COALESCE(#{j.field_success.to_s},false)=false
955
- AND COALESCE(#{j.field_times.to_s},0) < #{j.max_try_times.to_i}
1003
+ AND COALESCE(#{j.field_times.to_s},0) >= #{j.max_try_times.to_i}
956
1004
  "
957
- DB[q].first[:n].to_i
958
- end # def idle
1005
+ return DB[q].first[:n].to_i
1006
+ else
1007
+ return self.failed_function.call
1008
+ end
1009
+ end # def falsed
959
1010
 
960
- # reporting method: running
961
- # return the number of running tasks.
1011
+ # reporting method: timeline
1012
+ # Return an array of hashes with the number of successfull processed taasks in the last period.
1013
+ # The period is defined by the `scale_unit` and `scale_points` parameters.
1014
+ # The `scale_unit` can be `minutes`, `hours`, `days`, `weeks`, `months`, `years`.
1015
+ # The `scale_points` is the number of `scale_unit` to be reported, and it must be an integer higer than 0.
962
1016
  # if the numbr if running tasks is higher than `max_tasks_to_show` then it returns `max_tasks_to_show`+.
963
- def failed
1017
+ def timeline(scale_unit='minutes', scale_points=60)
964
1018
  j = self
965
- q = "
1019
+ a = []
1020
+ # validate: The period is defined by the `scale_unit` and `scale_points` parameters.
1021
+ if !['minutes', 'hours', 'days', 'weeks', 'months', 'years'].include?(scale_unit)
1022
+ raise "Invalid scale_unit: #{scale_unit}"
1023
+ end
1024
+ # validate: The `scale_points` is the number of `scale_unit` to be reported, and it must be an integer higer than 0.
1025
+ if !scale_points.is_a?(Integer) || scale_points<=0
1026
+ raise "Invalid scale_points: #{scale_points}"
1027
+ end
1028
+ # generate report
1029
+ point = 0
1030
+ while point<scale_points
1031
+ point += 1
1032
+ q = "
966
1033
  SELECT COUNT(*) AS n
967
- FROM #{j.table.to_s}
968
- WHERE COALESCE(#{j.field_success.to_s},false)=false
969
- AND COALESCE(#{j.field_times.to_s},0) >= #{j.max_try_times.to_i}
970
- "
971
- DB[q].first[:n].to_i
972
- end # def falsed
1034
+ FROM #{j.table.to_s}
1035
+ WHERE COALESCE(#{j.field_success.to_s},false)=true
1036
+ AND #{j.field_time.to_s} >= CAST('#{BlackStack::Pampa.now - point.send(scale_unit)}' AS TIMESTAMP)
1037
+ AND #{j.field_time.to_s} < CAST('#{BlackStack::Pampa.now - (point-1).send(scale_unit)}' AS TIMESTAMP)
1038
+ "
1039
+ a << { :time => BlackStack::Pampa.now - (point-1).send(scale_unit), :n => DB[q].first[:n].to_i }
1040
+ end # while point<scale_points
1041
+ # return
1042
+ a
1043
+ end # def timeline
973
1044
 
974
1045
  # reporting method: error_descriptions
975
1046
  # return an array of hashes { :id, :error_description } with the tasks that have an the success flag in false, error description.
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.27
4
+ version: 2.0.29
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-06-17 00:00:00.000000000 Z
11
+ date: 2023-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -70,26 +70,6 @@ dependencies:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
72
  version: 1.2.11
73
- - !ruby/object:Gem::Dependency
74
- name: blackstack-deployer
75
- requirement: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - "~>"
78
- - !ruby/object:Gem::Version
79
- version: 1.2.24
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 1.2.24
83
- type: :runtime
84
- prerelease: false
85
- version_requirements: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 1.2.24
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: 1.2.24
93
73
  - !ruby/object:Gem::Dependency
94
74
  name: simple_command_line_parser
95
75
  requirement: !ruby/object:Gem::Requirement