pampa_dispatcher 1.1.2 → 1.1.3
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.
- checksums.yaml +4 -4
- data/lib/pampa_dispatcher.rb +14 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75c67b38707d48672418adbafa79bbc6c06aca5c
|
4
|
+
data.tar.gz: 4cbc979f1537fd8412ed53892236539c372be929
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd0f4234aaafc8f553d81c994992a30c62c1c21fbb61cb79f9913c9064cba73122743757b52e533e196671fc144c873b62342c7029bc4ddf5052b537a12f5b79
|
7
|
+
data.tar.gz: 3aa676619f2e1a6d86d1a7475d1b19482fdc0a874a1ddc2b084ce495f67ab0f3a650d9f3178db72aac8cdc85734530153f29ee4d9b1a9ae39da70e100ee6fe96
|
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
|
|
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.3
|
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-
|
11
|
+
date: 2020-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket
|