rescheduler 0.5.1 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e0575537baa956f4e8628a7892d9bcc0c3c6a80
4
- data.tar.gz: 1481a1e1b3f2f4e491787793466db8479235ff61
3
+ metadata.gz: 85c352b4ca6259305ae8fa32ba0fc16c0c00aef0
4
+ data.tar.gz: 7d54913d094dced68ae4210a791471e022495aad
5
5
  SHA512:
6
- metadata.gz: 2107fe553f4b8a9570b8623d5d46b46552d8ead112201c7d80dd62df309ad280b3fb9d3c3876995ac02674a035e02f6d5f2653e959b03b346fdf589e2600c26a
7
- data.tar.gz: f897e041abbab34c119c70aad94c9333c4f4c94b52d72940b72483844d2be4f38eea31de2d38bc91401c6e2f7c9e3083db0b2b1b014926f1d383a7f5c715a844
6
+ metadata.gz: 6625da10818cf1aefdc48e3561c17c93d059939225bfdb784b0267771fc6b23db4d0ca89bff2b19fa112fa3bf2a5ad309624323dcf14dd09adb13cd75cc4ff3a
7
+ data.tar.gz: a6838adb3e3e6f1618df27dbce9f6a9d361539ecebd173e1a458e0dcf2008e6a3ebc42728835e9d63e0b8791a09804de4f2929579bdb5af57bbd957232d755c2
@@ -1,50 +1,53 @@
1
- #!/usr/bin/env ruby
2
- =begin
3
- rescheduler_launch <options> [<worker_name> <jobs.rb>]
4
- Options:
5
- --rails=<folder> Use rails environment from the givne folder
6
- --log=<file> Specify logfile (in Rails mode default to <rails_foler>/log/<worker_name>.log)
7
- --env=<env> Set these ENV into the new process
8
- --debug Do not daemonize or redirect output, work with current STDOUT
9
- --respawn_jobs=N Respawn worker after N jobs
10
- --respawn_time=N Respawn every N seconds (NOTE: Only will respawn after finish a job)
11
- Internal purpose only:
12
- --respawn Set to indicate this is a respawn of the named worker and will take over the
13
- name without deleting stats
14
- =end
15
-
16
- # First parse options
17
- opts = {}
18
- while ARGV.size > 0 && ARGV[0][0..1] == '--'
19
- opt,val = ARGV.shift[2..-1].split('=',2)
20
- val ||= true
21
- opts[opt] = val
22
- end
23
-
24
- opts['worker_name'] = ARGV.shift
25
- opts['worker_file'] = ARGV.shift
26
-
27
- abort "rescheduler_launch <options> <worker_name> <jobs.rb>" unless opts['worker_file'] && File.exists?(opts['worker_file'])
28
-
29
- # Daemonize first before we load rails
30
- begin
31
- Process.daemon unless opts['debug'] # Do not daemonize if debugging
32
- rescue NotImplementedError
33
- # This happens in windows, it is OK
34
- end
35
-
36
- # Load rails environment if --rails is specified
37
- require File.join(opts['rails'], 'config/environment.rb') if opts['rails']
38
-
39
- # Load rescheduler
40
- require File.expand_path('../../lib/rescheduler', __FILE__)
41
-
42
- Rescheduler::Worker.register(opts)
43
- Rescheduler::Worker.redirect_logging(opts) unless opts['debug']
44
-
45
- # Running the job file
46
- begin
47
- Kernel.load opts['worker_file']
48
- ensure
49
- Rescheduler::Worker.unregister unless Rescheduler::Worker.respawn_if_requested
50
- end
1
+ #!/usr/bin/env ruby
2
+ =begin
3
+ rescheduler_launch <options> [<worker_name> <jobs.rb>]
4
+ Options:
5
+ --rails=<folder> Use rails environment from the givne folder
6
+ --log=<file> Specify logfile (in Rails mode default to <rails_foler>/log/<worker_name>.log)
7
+ --env=<env> Set these ENV into the new process
8
+ --debug Do not daemonize or redirect output, work with current STDOUT
9
+ --respawn_jobs=N Respawn worker after N jobs
10
+ --respawn_time=N Respawn every N seconds (NOTE: Only will respawn after finish a job)
11
+ Internal purpose only:
12
+ --respawn Set to indicate this is a respawn of the named worker and will take over the
13
+ name without deleting stats
14
+ =end
15
+
16
+ # First parse options
17
+ opts = {}
18
+ while ARGV.size > 0 && ARGV[0][0..1] == '--'
19
+ opt,val = ARGV.shift[2..-1].split('=',2)
20
+ val ||= true
21
+ opts[opt] = val
22
+ end
23
+
24
+ opts['worker_name'] = ARGV.shift
25
+ opts['worker_file'] = ARGV.shift
26
+
27
+ abort "rescheduler_launch <options> <worker_name> <jobs.rb>" unless opts['worker_file'] && File.exists?(opts['worker_file'])
28
+
29
+ # Daemonize first before we load rails
30
+ begin
31
+ Process.daemon unless opts['debug'] # Do not daemonize if debugging
32
+ rescue NotImplementedError
33
+ # This happens in windows, it is OK
34
+ end
35
+
36
+ # Load rails environment if --rails is specified
37
+ require File.join(opts['rails'], 'config/environment.rb') if opts['rails']
38
+
39
+ # Load rescheduler
40
+ require File.expand_path('../../lib/rescheduler', __FILE__)
41
+
42
+ Rescheduler::Worker.register(opts)
43
+ Rescheduler::Worker.redirect_logging(opts) unless opts['debug']
44
+
45
+ Rescheduler.log_debug "[#{Rescheduler::Worker.worker_name}] Launching"
46
+
47
+
48
+ # Running the job file
49
+ begin
50
+ Kernel.load opts['worker_file']
51
+ ensure
52
+ Rescheduler::Worker.unregister unless Rescheduler::Worker.respawn_if_requested
53
+ end
@@ -345,6 +345,7 @@ module Rescheduler
345
345
  # Logging facility
346
346
  def log_debug(msg)
347
347
  return if config[:silent]
348
+ msg = msg.encode('UTF-8', invalid: :replace, undef: :replace)
348
349
  print("#{Time.now.iso8601} #{msg}\n")
349
350
  STDOUT.flush
350
351
  end
@@ -147,16 +147,16 @@ module Rescheduler
147
147
 
148
148
  def register(opt)
149
149
  @launch_options = opt # Save for respawning
150
- name_pattern = opt['worker_name']
151
-
152
- last_wname = nil
153
- widx = 0 # We do not preserve worker_index upon respawn
154
- wname = nil
155
- if opt['respawn']
156
- wname = name_pattern
150
+ if @launch_options['respawn']
151
+ wname = @launch_options['worker_name']
157
152
  # Reset created for respawn purposes.
158
153
  redis.hset(rk_worker(wname), 'created', Time.now.to_i)
159
154
  else
155
+ name_pattern = @launch_options['worker_name']
156
+
157
+ widx = 0 # We do not preserve worker_index upon respawn
158
+ wname = nil
159
+ last_wname = nil
160
160
  loop do
161
161
  wname = name_pattern.gsub('%', widx.to_s)
162
162
  if wname == last_wname # For the name without %, we add one to the end if clashes
@@ -168,9 +168,9 @@ module Rescheduler
168
168
  widx += 1
169
169
  last_wname = wname
170
170
  end
171
+ @launch_options['worker_name'] = wname # Save this in launch options
172
+ @launch_options['worker_index'] = widx # Sequence of the same worker
171
173
  end
172
- @launch_options['worker_name'] = wname # Save this in launch options
173
- @launch_options['worker_index'] = widx # Sequence of the same worker
174
174
  @launch_options['pid'] = Process.pid
175
175
  @launch_options['machine'] = Socket.gethostname
176
176
 
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rescheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dongyi Liao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-04 00:00:00.000000000 Z
11
+ date: 2016-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: multi_json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1'
41
41
  description: Rescheduler is a library that uses Redis to maintain a task queue of
42
42
  immediate and delayed jobs without polling.
43
43
  email: liaody@gmail.com
@@ -52,7 +52,7 @@ files:
52
52
  - lib/rescheduler/worker.rb
53
53
  homepage: https://github.com/liaody/rescheduler
54
54
  licenses:
55
- - BSD
55
+ - MIT
56
56
  metadata: {}
57
57
  post_install_message:
58
58
  rdoc_options: []