pampa 2.0.27 → 2.0.28

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 -39
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 766a4c8e58dcd60e3938ae32600b3715f696418c7f4f2d4cb15ea22fa8559213
4
- data.tar.gz: 2a131d44bba1996839e5fc03a0a12148c6429d49b050a711c4bcc91a00fe34b2
3
+ metadata.gz: 1c23aeba3d2dcdf2d7a926dac7928c3bf146cc918039af21b65e39c05efb4277
4
+ data.tar.gz: ea623e27340b7d9b16cb641d6c52a6bef7a5c46ccece769509e0d60eb5cfda8c
5
5
  SHA512:
6
- metadata.gz: 3e8bc763b08173e152f9a7a6fdc3c75fa1aca6e2522cba7b919fa2b5c6f71653266fc7f2e29fbfc749a59af706bf3cb63624ef8ce4da903349ae7001c4c5aad1
7
- data.tar.gz: d03a80fcd845fe760be93a42b720528cc518fd1380cee51dc1d1ab2439254d23ed2ef6c42acf4075b9290f513151486b28c90bf7c568731516a29394a1859db9
6
+ metadata.gz: bdea50dcd8bd45c8f92d24200c84c49d4602785b5f8258bb21a63db10d42ebb945219f6e5b4d6d380e7b4cab6db6f85c18a18fd7c7c71dcf2989869d09298e1a
7
+ data.tar.gz: 6bd6dd58d85bc9502383eb42c3aa7a0f2700ab68ab761a736a63a179e86f4652f783c696ae91e95ea12b8a04777bea4a54d83857a478baa9e03b705dc67fb32b
data/lib/pampa.rb CHANGED
@@ -177,8 +177,8 @@ module BlackStack
177
177
  assigned = BlackStack::Pampa.workers.select { |worker| worker.attached && worker.assigned_job.to_s == job.name.to_s }
178
178
  l.logf("done (#{assigned.size.to_s})")
179
179
 
180
- l.logs("Getting total pending (idle) tasks... ")
181
- pendings = job.idle
180
+ l.logs("Getting total pending (pending) tasks... ")
181
+ pendings = job.pending
182
182
  l.logf("done (#{pendings.to_s})")
183
183
 
184
184
  l.logs("0 pending tasks?.... ")
@@ -632,6 +632,9 @@ module BlackStack
632
632
  # max number of times that a record can start to process & fail (:start_time field is not nil,
633
633
  # but :end_time field is still nil after :max_job_duration_minutes)
634
634
  attr_accessor :max_try_times
635
+
636
+ # CUSTOM DISPATCHING FUNCTIONS
637
+ #
635
638
  # additional function to returns an array of tasks pending to be processed by a worker.
636
639
  # it should returns an array
637
640
  # keep it nil if you want to run the default function
@@ -661,9 +664,23 @@ module BlackStack
661
664
  attr_accessor :finisher_function
662
665
  # Function to execute for each task.
663
666
  attr_accessor :processing_function
667
+
668
+ # CUSTOM REPORTING FUNCTIONS
669
+ #
670
+ # additional function to returns the number of total tasks.
671
+ # it should returns an array
672
+ # keep it nil if you want to run the default function
673
+ attr_accessor :total_function
674
+ attr_accessor :completed_function
675
+ attr_accessor :pending_function
676
+ attr_accessor :failed_function
677
+
678
+ # ELASTIC WORKERS ASSIGNATION
679
+ #
664
680
  # stretch assignation/unassignation of workers
665
681
  attr_accessor :max_pending_tasks
666
682
  attr_accessor :max_assigned_workers
683
+
667
684
  # choose workers to assign tasks
668
685
  attr_accessor :filter_worker_id
669
686
 
@@ -683,6 +700,8 @@ module BlackStack
683
700
  :queue_size => self.queue_size,
684
701
  :max_job_duration_minutes => self.max_job_duration_minutes,
685
702
  :max_try_times => self.max_try_times,
703
+
704
+ # dispatching custom functions
686
705
  :occupied_function => self.occupied_function.to_s,
687
706
  :allowing_function => self.allowing_function.to_s,
688
707
  :selecting_function => self.selecting_function.to_s,
@@ -693,7 +712,13 @@ module BlackStack
693
712
  :processing_function => self.processing_function.to_s,
694
713
  :max_pending_tasks => self.max_pending_tasks,
695
714
  :max_assigned_workers => self.max_assigned_workers,
696
- :filter_worker_id => self.filter_worker_id
715
+ :filter_worker_id => self.filter_worker_id,
716
+
717
+ # reporting custom functions
718
+ :total_function => self.total_function.to_s,
719
+ :completed_function => self.completed_function.to_s,
720
+ :pending_function => self.pending_function.to_s,
721
+ :failed_function => self.failed_function.to_s,
697
722
  }
698
723
  end
699
724
 
@@ -721,12 +746,22 @@ module BlackStack
721
746
  self.queue_size = h[:queue_size]
722
747
  self.max_job_duration_minutes = h[:max_job_duration_minutes]
723
748
  self.max_try_times = h[:max_try_times]
749
+
750
+ # dispatching custom functions
724
751
  self.occupied_function = h[:occupied_function]
725
752
  self.allowing_function = h[:allowing_function]
726
753
  self.selecting_function = h[:selecting_function]
727
754
  self.relaunching_function = h[:relaunching_function]
728
755
  self.relauncher_function = h[:relauncher_function]
729
756
  self.processing_function = h[:processing_function]
757
+
758
+ # reporting custom functions
759
+ self.total_function = h[:total_function]
760
+ self.completed_function = h[:completed_function]
761
+ self.pending_function = h[:pending_function]
762
+ self.failed_function = h[:failed_function]
763
+
764
+ # elastic workers assignation
730
765
  self.max_pending_tasks = h[:max_pending_tasks]
731
766
  self.max_assigned_workers = h[:max_assigned_workers]
732
767
  self.filter_worker_id = h[:filter_worker_id]
@@ -914,62 +949,112 @@ module BlackStack
914
949
  return i
915
950
  end
916
951
 
917
- # reporting methods
918
- # idle + failed + completed = total
952
+ # reporting methods
953
+ #
919
954
 
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`+.
955
+ # reporting method: total
956
+ # reutrn the number of total tasks.
957
+ # if the numbr if total tasks is higher than `max_tasks_to_show` then it returns `max_tasks_to_show`+.
923
958
  def total
924
959
  j = self
925
- q = "
926
- SELECT COUNT(*) AS n
927
- FROM #{j.table.to_s}
928
- "
929
- DB[q].first[:n].to_i
960
+ if self.total_function.nil?
961
+ q = "
962
+ SELECT COUNT(*) AS n
963
+ FROM #{j.table.to_s}
964
+ "
965
+ return DB[q].first[:n].to_i
966
+ else
967
+ return self.total_function.call
968
+ end
930
969
  end # def total
931
970
 
932
971
 
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`+.
972
+ # reporting method: completed
973
+ # reutrn the number of completed tasks.
974
+ # if the numbr if completed tasks is higher than `max_tasks_to_show` then it returns `max_tasks_to_show`+.
936
975
  def completed
937
976
  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
977
+ if self.completed_function.nil?
978
+ q = "
979
+ SELECT COUNT(*) AS n
980
+ FROM #{j.table.to_s}
981
+ WHERE COALESCE(#{j.field_success.to_s},false)=true
982
+ "
983
+ return DB[q].first[:n].to_i
984
+ else
985
+ return self.completed_function.call
986
+ end
944
987
  end # def completed
945
988
 
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
989
+ # reporting method: pending
990
+ # reutrn the number of pending tasks.
991
+ # if the numbr if pending tasks is higher than `max_tasks_to_show` then it returns `max_tasks_to_show`+.
992
+ def pending
950
993
  j = self
994
+ if self.pending_function.nil?
995
+ q = "
996
+ SELECT COUNT(*) AS n
997
+ FROM #{j.table.to_s}
998
+ WHERE COALESCE(#{j.field_success.to_s},false)=false
999
+ AND COALESCE(#{j.field_times.to_s},0) < #{j.max_try_times.to_i}
1000
+ "
1001
+ return DB[q].first[:n].to_i
1002
+ else
1003
+ return self.pending_function.call
1004
+ end
1005
+ end # def pending
1006
+
1007
+ # reporting method: running
1008
+ # return the number of running tasks.
1009
+ # if the number if running tasks is higher than `max_tasks_to_show` then it returns `max_tasks_to_show`+.
1010
+ def failed
1011
+ j = self
1012
+ if self.failed_function.nil?
951
1013
  q = "
952
1014
  SELECT COUNT(*) AS n
953
1015
  FROM #{j.table.to_s}
954
1016
  WHERE COALESCE(#{j.field_success.to_s},false)=false
955
- AND COALESCE(#{j.field_times.to_s},0) < #{j.max_try_times.to_i}
1017
+ AND COALESCE(#{j.field_times.to_s},0) >= #{j.max_try_times.to_i}
956
1018
  "
957
- DB[q].first[:n].to_i
958
- end # def idle
1019
+ return DB[q].first[:n].to_i
1020
+ else
1021
+ return self.failed_function.call
1022
+ end
1023
+ end # def falsed
959
1024
 
960
- # reporting method: running
961
- # return the number of running tasks.
1025
+ # reporting method: timeline
1026
+ # Return an array of hashes with the number of successfull processed taasks in the last period.
1027
+ # The period is defined by the `scale_unit` and `scale_points` parameters.
1028
+ # The `scale_unit` can be `minutes`, `hours`, `days`, `weeks`, `months`, `years`.
1029
+ # The `scale_points` is the number of `scale_unit` to be reported, and it must be an integer higer than 0.
962
1030
  # if the numbr if running tasks is higher than `max_tasks_to_show` then it returns `max_tasks_to_show`+.
963
- def failed
1031
+ def timeline(scale_unit='minutes', scale_points=60)
964
1032
  j = self
965
- q = "
1033
+ a = []
1034
+ # validate: The period is defined by the `scale_unit` and `scale_points` parameters.
1035
+ if !['minutes', 'hours', 'days', 'weeks', 'months', 'years'].include?(scale_unit)
1036
+ raise "Invalid scale_unit: #{scale_unit}"
1037
+ end
1038
+ # validate: The `scale_points` is the number of `scale_unit` to be reported, and it must be an integer higer than 0.
1039
+ if !scale_points.is_a?(Integer) || scale_points<=0
1040
+ raise "Invalid scale_points: #{scale_points}"
1041
+ end
1042
+ # generate report
1043
+ point = 0
1044
+ while point<scale_points
1045
+ point += 1
1046
+ q = "
966
1047
  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
1048
+ FROM #{j.table.to_s}
1049
+ WHERE COALESCE(#{j.field_success.to_s},false)=true
1050
+ AND #{j.field_time.to_s} >= CAST('#{BlackStack::Pampa.now - point.send(scale_unit)}' AS TIMESTAMP)
1051
+ AND #{j.field_time.to_s} < CAST('#{BlackStack::Pampa.now - (point-1).send(scale_unit)}' AS TIMESTAMP)
1052
+ "
1053
+ a << { :time => BlackStack::Pampa.now - (point-1).send(scale_unit), :n => DB[q].first[:n].to_i }
1054
+ end # while point<scale_points
1055
+ # return
1056
+ a
1057
+ end # def timeline
973
1058
 
974
1059
  # reporting method: error_descriptions
975
1060
  # 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.28
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-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel