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.
- checksums.yaml +4 -4
- data/lib/pampa_dispatcher.rb +16 -17
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c1dc9cc0ade4f72c76c703576a5af20acc84138
|
4
|
+
data.tar.gz: 0ed72d048112a98c3b4e35db65781a7e29f34428
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c42f4220c1290e1dead31f9ab25cf0286d352da5c907122b62f47290832401ab3233726c371c1aa665da1414f5447e2bbb17d46064b2dae385ec3f01020ba80b
|
7
|
+
data.tar.gz: 516b95b3c8e461a629d08ea7534d7cd80ac294287e0305bb22899d4147891f83db34cceb0d294f9e1f3971fb3be15869774746edd3c8bea317a8d37bdd1431d0
|
data/lib/pampa_dispatcher.rb
CHANGED
@@ -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
|
25
|
-
# it should returns an
|
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 :
|
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.
|
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
|
-
#
|
74
|
-
# it will
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
return self.table.where(self.field_id.to_sym => worker.id
|
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.
|
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
|
-
|
87
|
+
occupied = self.occupied_slots(worker).size
|
89
88
|
allowed = self.queue_size
|
90
|
-
if
|
89
|
+
if occupied > allowed
|
91
90
|
return 0
|
92
91
|
else
|
93
|
-
return allowed -
|
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.
|
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
|
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.
|
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:
|
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.
|
99
|
+
version: 1.1.24
|
100
100
|
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: 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.
|
109
|
+
version: 1.1.24
|
110
110
|
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
version: 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: []
|