pampa_dispatcher 1.1.2 → 1.1.6

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 +19 -17
  3. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3fecfc8011a8887bdc3e98dc2337c8fd816c839
4
- data.tar.gz: 27de7b420a6f87d2029abec0639cf7ba93bb165f
3
+ metadata.gz: 52492731329288d88868fa62bf58e49517f101f3
4
+ data.tar.gz: 394a19162ed3d00a91cbd91a7d9e868b8fdf5fa3
5
5
  SHA512:
6
- metadata.gz: f6e3f31ddd0c2b2748ebb6d7b27cd3d49c89e5572152a2c8d3f6d794f056a20c1f79a958e32f65b8de95bb729984bdccd46d2d286513837aff64a1924253bb6e
7
- data.tar.gz: 928f0a664d9f9c7ea8a9c783a9d3551d8f67275c744d4802d54e12c452220af8ee05fa1c6945efdfbe279315c1e52aa9b79b5f63d27d7f2f075c50d3c2d1289e
6
+ metadata.gz: 09c574706a73bb3371bd4b4060993ab50e4afa98c6f67c97868fd2c23eef90529690d74ddd42bc8aaeeb8edf28597254877e471f78052309ef74dd3bad3061c4
7
+ data.tar.gz: 47f68c81589d15decb37e3ffa9da92d1c1230001e440bce204925bbc4c13587abb41a10b2e5c98bd6f37819dbc2e4e70150dde446befcc75e6d34e3d3cc0e558
@@ -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
@@ -127,10 +126,13 @@ module BlackStack
127
126
  # choose the records to retry
128
127
  # returns an array of IDs
129
128
  def relaunching_dataset(worker, n)
130
- ds = self.table.select(self.field_primary_key.to_sym).where("#{self.field_time.to_s} < '#{(Time.now - 60*self.max_job_duration_minutes.to_i).strftime('%Y-%m-%d %H:%M:%S').to_s}'")
129
+ ds = self.table.select(self.field_primary_key.to_sym).where("#{self.field_time.to_s} < DATEADD(mi, -#{self.max_job_duration_minutes.to_i}, GETDATE())")
131
130
  ds = ds.filter("#{self.field_end_time.to_s} IS NULL") if !self.field_end_time.nil?
132
131
  # ds = ds.filter("( #{self.field_times.to_s} IS NULL OR #{self.field_times.to_s} < #{self.max_try_times.to_s} ) ") if !self.field_times.nil?
133
132
  ds = ds.limit(n)
133
+ puts
134
+ puts "relaunching_dataset: #{ds.sql}"
135
+ ds
134
136
  end
135
137
 
136
138
  def relaunching(worker, n)
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.6
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: 2021-11-16 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: []