pampa_dispatcher 1.1.1 → 1.1.5

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_dispatcher.rb +16 -17
  3. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 854adb6af15723ba6c9a2f4ac5af8acc8a47f4ba
4
- data.tar.gz: 11091e316eab1a12bfb30114269ea612693aa59a
3
+ metadata.gz: 2c1dc9cc0ade4f72c76c703576a5af20acc84138
4
+ data.tar.gz: 0ed72d048112a98c3b4e35db65781a7e29f34428
5
5
  SHA512:
6
- metadata.gz: a89cd5510431a901f9677bd35cceabcf20d281e0d514f1063cc83c514335a6998ae14109ea15078e455d61853ac63358bbc0ee86a7a637b5fe4faff5bc81ab82
7
- data.tar.gz: 324445697c97efa5ed2089e43326a9363165a7d7db044929d07eacf9834cbf3c2526bfb56d7b77e1475196f058c350d92aa6cabab8ac895c3250b23b8e7a3bbc
6
+ metadata.gz: c42f4220c1290e1dead31f9ab25cf0286d352da5c907122b62f47290832401ab3233726c371c1aa665da1414f5447e2bbb17d46064b2dae385ec3f01020ba80b
7
+ data.tar.gz: 516b95b3c8e461a629d08ea7534d7cd80ac294287e0305bb22899d4147891f83db34cceb0d294f9e1f3971fb3be15869774746edd3c8bea317a8d37bdd1431d0
@@ -21,10 +21,10 @@ module BlackStack
21
21
  # max number of times that a record can start to process & fail (:start_time field is not nil,
22
22
  # but :end_time field is still nil after :max_job_duration_minutes)
23
23
  attr_accessor :max_try_times
24
- # additional function to decide how many records are pending for processing
25
- # it should returns an integer
24
+ # additional function to returns an array of objects pending to be processed by a worker.
25
+ # it should returns an array
26
26
  # keep it nil if you want to run the default function
27
- attr_accessor :ocuppied_function
27
+ attr_accessor :occupied_function
28
28
  # additional function to decide if the worker can dispatch or not
29
29
  # example: use this function when you want to decide based on the remaining credits of the client
30
30
  # it should returns true or false
@@ -63,34 +63,33 @@ module BlackStack
63
63
  self.queue_size = h[:queue_size]
64
64
  self.max_job_duration_minutes = h[:max_job_duration_minutes]
65
65
  self.max_try_times = h[:max_try_times]
66
- self.ocuppied_function = h[:ocuppied_function]
66
+ self.occupied_function = h[:occupied_function]
67
67
  self.allowing_function = h[:allowing_function]
68
68
  self.selecting_function = h[:selecting_function]
69
69
  self.relaunching_function = h[:relaunching_function]
70
70
  self.relauncher_function = h[:relauncher_function]
71
71
  end
72
72
 
73
- # decide how many records are pending for processing
74
- # it will count the number if records with :reservation_id == worker.id, and :start_time == nil
75
- # it returns an integer
76
- def ocuppied_slots(worker)
77
- if self.ocuppied_function.nil?
78
- return self.table.where(self.field_id.to_sym => worker.id, self.field_start_time.to_sym => nil).count if !self.field_start_time.nil?
79
- return self.table.where(self.field_id.to_sym => worker.id).count if self.field_start_time.nil?
73
+ # returns an array of objects pending to be processed by the worker.
74
+ # it will select the records with :reservation_id == worker.id, and :start_time == nil
75
+ def occupied_slots(worker)
76
+ if self.occupied_function.nil?
77
+ return self.table.where(self.field_id.to_sym => worker.id, self.field_start_time.to_sym => nil).all if !self.field_start_time.nil?
78
+ return self.table.where(self.field_id.to_sym => worker.id).all if self.field_start_time.nil?
80
79
  else
81
80
  # TODO: validar que retorna un entero
82
- return self.ocuppied_function.call(worker, self)
81
+ return self.occupied_function.call(worker, self)
83
82
  end
84
83
  end
85
84
 
86
85
  # returns the number of free slots in the procesing queue of this worker
87
86
  def available_slots(worker)
88
- ocuppied = self.ocuppied_slots(worker)
87
+ occupied = self.occupied_slots(worker).size
89
88
  allowed = self.queue_size
90
- if ocuppied > allowed
89
+ if occupied > allowed
91
90
  return 0
92
91
  else
93
- return allowed - ocuppied
92
+ return allowed - occupied
94
93
  end
95
94
  end
96
95
 
@@ -116,7 +115,7 @@ module BlackStack
116
115
  end # selecting_dataset
117
116
 
118
117
  def selecting(worker, n)
119
- if self.allowing_function.nil?
118
+ if self.selecting_function.nil?
120
119
  return self.selecting_dataset(worker, n).map { |o| o[self.field_primary_key.to_sym] }
121
120
  else
122
121
  # TODO: validar que retorna un array de strings
@@ -153,7 +152,7 @@ module BlackStack
153
152
  def start(o)
154
153
  if self.starter_function.nil?
155
154
  o[self.field_start_time.to_sym] = now() if !self.field_start_time.nil?
156
- o[self.field_times.to_sym] = o[self.field_times.to_sym].to_i + 1 if !self.field_times.nil?
155
+ o[self.field_times.to_sym] = o[self.field_times.to_sym].to_i + 1
157
156
  o.save
158
157
  else
159
158
  self.starter_function.call(o, self)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pampa_dispatcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.5
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: 2020-01-02 00:00:00.000000000 Z
11
+ date: 2021-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket
@@ -96,20 +96,20 @@ dependencies:
96
96
  requirements:
97
97
  - - "~>"
98
98
  - !ruby/object:Gem::Version
99
- version: 1.1.1
99
+ version: 1.1.24
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
- version: 1.1.1
102
+ version: 1.1.24
103
103
  type: :runtime
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: 1.1.1
109
+ version: 1.1.24
110
110
  - - ">="
111
111
  - !ruby/object:Gem::Version
112
- version: 1.1.1
112
+ version: 1.1.24
113
113
  description: 'THIS GEM IS STILL IN DEVELOPMENT STAGE. Find documentation here: https://github.com/leandrosardi/pampa_dispatcher.'
114
114
  email: leandro.sardi@expandedventure.com
115
115
  executables: []