myreplicator 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,18 +36,20 @@ module Myreplicator
36
36
  ##
37
37
  def self.perform(export_id, *args)
38
38
  options = args.extract_options!
39
+ ActiveRecord::Base.verify_active_connections!
40
+ ActiveRecord::Base.connection.reconnect!
39
41
  export_obj = Export.find(export_id)
40
- export_obj.export_table
41
- end
42
-
43
- ##
44
- # Runs the export process using the required Exporter library
45
- ##
46
- def export_table
47
- Log.run(:job_type => "export", :name => schedule_name,
42
+ export_obj.export
43
+ end
44
+
45
+ ##
46
+ # Runs the export process using the required Exporter library
47
+ ##
48
+ def export
49
+ Log.run(:job_type => "export", :name => schedule_name,
48
50
  :file => filename, :export_id => id) do |log|
49
51
  exporter = MysqlExporter.new
50
- exporter.export_table self
52
+ exporter.export_table self # pass current object to exporter
51
53
  end
52
54
  end
53
55
 
@@ -59,8 +59,12 @@ module Myreplicator
59
59
  def kill
60
60
  begin
61
61
  Process.kill('TERM', pid)
62
+ self.state = "killed"
63
+ self.save!
62
64
  rescue Errno::ESRCH
63
65
  puts "pid #{pid} does not exist!"
66
+ self.state = "dead-pid"
67
+ self.save!
64
68
  end
65
69
  end
66
70
 
@@ -1,3 +1,3 @@
1
1
  module Myreplicator
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -29,17 +29,16 @@ module Myreplicator
29
29
  def run
30
30
  @done = false
31
31
  @manager_running = false
32
+ reaper = nil
32
33
 
33
34
  while @queue.size > 0
34
35
  if @threads.size <= @max_threads
35
36
  @threads << Thread.new(@queue.pop) do |proc|
36
- Thread.current[:status] = 'running' # Manually Set Thread state for Checks
37
37
  @klass.new.instance_exec(proc[:params], &proc[:block])
38
- Thread.current[:status] = 'done'
39
38
  end
40
39
  else
41
40
  unless @manager_running
42
- manage_threads
41
+ reaper = manage_threads
43
42
  @manager_running = true
44
43
  end
45
44
  sleep 1
@@ -47,14 +46,11 @@ module Myreplicator
47
46
  end
48
47
 
49
48
  # Run manager if thread size never reached max
50
- manage_threads unless @manager_running
49
+ reaper = manage_threads unless @manager_running
51
50
 
52
51
  # Waits until all threads are completed
53
52
  # Before exiting
54
- while !done?
55
- sleep 1
56
- end
57
-
53
+ reaper.join
58
54
  end
59
55
 
60
56
  ##
@@ -67,9 +63,8 @@ module Myreplicator
67
63
  while(@threads.size > 0)
68
64
  done = []
69
65
  @threads.each do |t|
70
- done << t if t[:status] == "done"
66
+ done << t if t.stop?
71
67
  end
72
-
73
68
  done.each{|d| @threads.delete(d)} # Clear dead threads
74
69
 
75
70
  # If no more jobs are left, mark done
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myreplicator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-16 00:00:00.000000000 Z
12
+ date: 2013-01-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -344,7 +344,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
344
344
  version: '0'
345
345
  segments:
346
346
  - 0
347
- hash: -2633228139332231140
347
+ hash: -2453224116345445588
348
348
  required_rubygems_version: !ruby/object:Gem::Requirement
349
349
  none: false
350
350
  requirements:
@@ -353,7 +353,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
353
353
  version: '0'
354
354
  segments:
355
355
  - 0
356
- hash: -2633228139332231140
356
+ hash: -2453224116345445588
357
357
  requirements: []
358
358
  rubyforge_project:
359
359
  rubygems_version: 1.8.23