pampa_dispatcher 1.1.2 → 1.1.3

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