ncr-background_fu 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ === 1.0.9 / 2008-10-22
2
+
3
+ * Merged a few important fixes from Keith Morrison. Bumped version, fixed gemspec (thanks 森山 誠二郎). Closes #4. [Keith Morrison, 森山 誠二郎, ncr]
4
+
5
+ === Master / 2008-07-31
6
+
7
+ * Make it clear that generated views are meant to be used when bonus features are enabled. [Trevor Turk, ncr]
8
+
1
9
  === 1.0.8 / 2008-07-30
2
10
 
3
11
  * Reverted back to "text" column for storing job results so it works on PostgreSQL. [Trevor Turk, ncr]
data/README.txt CHANGED
@@ -17,7 +17,7 @@ Background tasks in Ruby On Rails made dead simple.
17
17
  * Clean and straightforward approach (database-based priority queue).
18
18
  * Uses database table (migration included) to store jobs reliably.
19
19
  * Capistrano tasks included.
20
- * Generators with migrations and example views included.
20
+ * Generators with migrations and example views included (to be used with concurrency enabled).
21
21
  * Multiple worker daemons available.
22
22
  * Easy to deploy in distributed environments.
23
23
  * Enables prioritizing and simple scheduling.
@@ -131,6 +131,8 @@ in your environment.
131
131
  These features are:
132
132
  * monitoring progress (perfect for ajax progress bars)
133
133
  * stopping a running worker in a merciful way.
134
+
135
+ Generated admin views are meant to be used only when bonus features (concurrency) are enabled.
134
136
 
135
137
  Read the code (short and easy) to discover them.
136
138
 
@@ -1,16 +1,16 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{background_fu}
3
- s.version = "1.0.8"
3
+ s.version = "1.0.9"
4
4
 
5
5
  s.specification_version = 2 if s.respond_to? :specification_version=
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jacek Becela"]
9
- s.date = %q{2008-05-28}
9
+ s.date = %q{2008-10-22}
10
10
  s.description = %q{Background tasks in Ruby On Rails made dead simple.}
11
11
  s.email = ["jacek.becela@gmail.com"]
12
12
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
13
- s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "background-fu.gemspec", "generators/background/USAGE", "generators/background/background_generator.rb", "generators/background/templates/background.rb", "generators/background/templates/background_ctl", "generators/background/templates/daemons", "generators/background/templates/daemons.yml", "generators/background/templates/example_monitored_worker.rb", "generators/background/templates/example_worker.rb", "generators/background/templates/migration.rb", "generators/background/templates/scaffold/_job.html.erb", "generators/background/templates/scaffold/_job_deleted.html.erb", "generators/background/templates/scaffold/_progress_indicator.html.erb", "generators/background/templates/scaffold/background_fu.css", "generators/background/templates/scaffold/index.html.erb", "generators/background/templates/scaffold/jobs.html.erb", "generators/background/templates/scaffold/jobs_controller.rb", "generators/background/templates/scaffold/jobs_helper.rb", "lib/background_fu.rb", "lib/background_fu/worker_monitoring.rb", "lib/job.rb", "lib/job/bonus_features.rb", "rails/init.rb"]
13
+ s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "background-fu.gemspec", "generators/background/USAGE", "generators/background/background_generator.rb", "generators/background/templates/background.rb", "generators/background/templates/background_ctl", "generators/background/templates/daemons", "generators/background/templates/daemons.yml", "generators/background/templates/example_monitored_worker.rb", "generators/background/templates/example_worker.rb", "generators/background/templates/migration.rb", "generators/background/templates/scaffold/_form.html.erb", "generators/background/templates/scaffold/_job.html.erb", "generators/background/templates/scaffold/_job_deleted.html.erb", "generators/background/templates/scaffold/_progress_indicator.html.erb", "generators/background/templates/scaffold/application_controller.rb", "generators/background/templates/scaffold/background_fu.css", "generators/background/templates/scaffold/index.html.erb", "generators/background/templates/scaffold/jobs.html.erb", "generators/background/templates/scaffold/jobs_controller.rb", "generators/background/templates/scaffold/jobs_helper.rb", "generators/background/templates/scaffold/new.html.erb", "lib/background_fu.rb", "lib/background_fu/worker_monitoring.rb", "lib/job.rb", "lib/job/bonus_features.rb", "rails/init.rb"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/ncr/background-fu}
16
16
  s.rdoc_options = ["--main", "README.txt"]
@@ -11,7 +11,7 @@ else
11
11
  end
12
12
 
13
13
  loop do
14
- if job = Job.find(:first, :conditions => ["state='pending' and start_at <= ?", Time.now.utc], :order => "priority desc, start_at asc")
14
+ if job = Job.find(:first, :conditions => ["state='pending' and start_at <= ?", Time.now], :order => "priority desc, start_at asc")
15
15
  job.get_done!
16
16
  else
17
17
  RAILS_DEFAULT_LOGGER.info("BackgroundFu: Waiting for jobs...")
@@ -0,0 +1,10 @@
1
+ <%= error_messages_for :job %>
2
+ <% form_for(:job, :html => {:class => "job"}) do |f| %>
3
+ <%= f.label :worker_class %><br />
4
+ <%= f.text_field :worker_class, :class => "worker-class" %><br />
5
+ <%= f.label :worker_method %><br />
6
+ <%= f.text_field :worker_method, :class => "worker-method" %><br />
7
+ <%= f.label :args, "Args - each line (including empty) is interpreted as a string argument" %><br />
8
+ <%= f.text_area :args %><br />
9
+ <%= f.submit "Enqueue", :class => "button" %>
10
+ <% end %>
@@ -0,0 +1,2 @@
1
+ class Admin::ApplicationController < ApplicationController
2
+ end
@@ -0,0 +1,2 @@
1
+ <%= render :partial => "form", :locals => { :job => @job } %>
2
+ <%= link_to "Back to Jobs", admin_jobs_path %><br />
data/lib/background_fu.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module BackgroundFu
2
2
 
3
- VERSION = "1.0.8"
3
+ VERSION = "1.0.9"
4
4
 
5
5
  end
@@ -16,6 +16,7 @@ module Job::BonusFeatures
16
16
  invoke_worker_without_threads; nil
17
17
  end
18
18
 
19
+ self.reload
19
20
  self.state = res ? "stopped" : "finished"
20
21
  end
21
22
 
@@ -44,7 +45,7 @@ module Job::BonusFeatures
44
45
  end
45
46
  end
46
47
 
47
- # Overwritten because of new "stopped" state.
48
+ # Overridden because of new "stopped" state.
48
49
  def restart_with_threads!
49
50
  if stopped? || failed?
50
51
  update_attributes!(
@@ -57,13 +58,11 @@ module Job::BonusFeatures
57
58
  end
58
59
  end
59
60
 
60
- # This is the only place where multi-threading
61
- # is used in the plugin and is completely optional.
61
+ # Monitors the worker and updates the job progress. If the job's status
62
+ # is changed to 'stopping', the worker is requested to stop.
62
63
  def monitor_worker
63
64
  Thread.new do
64
- # 1. running? - check if not failed or finished.
65
- # 2. !Job.find(id).stopping? - check if someone ordered stopping the job.
66
- while(running? && !Job.find(id).stopping?)
65
+ while running? && !Job.find(id).stopping?
67
66
  current_progress = @worker.instance_variable_get("@progress")
68
67
 
69
68
  if current_progress == progress
@@ -74,11 +73,11 @@ module Job::BonusFeatures
74
73
  end
75
74
  end
76
75
 
77
- # If someone ordered stopping a job we infrom the worker that it should stop.
78
- if(Job.find(id).stopping?)
76
+ if Job.find(id).stopping?
79
77
  @worker.instance_variable_set("@stopping", true)
80
78
  end
81
79
  end
80
+
82
81
  logger.info("BackgroundFu: Job monitoring started. Job(id: #{id}).")
83
82
  end
84
83
 
data/lib/job.rb CHANGED
@@ -50,7 +50,7 @@ class Job < ActiveRecord::Base
50
50
  end
51
51
 
52
52
  def initialize_worker
53
- update_attributes!(:started_at => Time.now.utc, :state => "running")
53
+ update_attributes!(:started_at => Time.now, :state => "running")
54
54
  @worker = worker_class.constantize.new
55
55
  logger.info("BackgroundFu: Job initialized. Job(id: #{id}).")
56
56
  end
@@ -107,7 +107,7 @@ class Job < ActiveRecord::Base
107
107
  def setup_start_at
108
108
  return unless start_at.blank?
109
109
 
110
- self.start_at = Time.now.utc
110
+ self.start_at = Time.now
111
111
  end
112
112
 
113
113
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ncr-background_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacek Becela
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-28 00:00:00 -07:00
12
+ date: 2008-10-22 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -47,14 +47,17 @@ files:
47
47
  - generators/background/templates/example_monitored_worker.rb
48
48
  - generators/background/templates/example_worker.rb
49
49
  - generators/background/templates/migration.rb
50
+ - generators/background/templates/scaffold/_form.html.erb
50
51
  - generators/background/templates/scaffold/_job.html.erb
51
52
  - generators/background/templates/scaffold/_job_deleted.html.erb
52
53
  - generators/background/templates/scaffold/_progress_indicator.html.erb
54
+ - generators/background/templates/scaffold/application_controller.rb
53
55
  - generators/background/templates/scaffold/background_fu.css
54
56
  - generators/background/templates/scaffold/index.html.erb
55
57
  - generators/background/templates/scaffold/jobs.html.erb
56
58
  - generators/background/templates/scaffold/jobs_controller.rb
57
59
  - generators/background/templates/scaffold/jobs_helper.rb
60
+ - generators/background/templates/scaffold/new.html.erb
58
61
  - lib/background_fu.rb
59
62
  - lib/background_fu/worker_monitoring.rb
60
63
  - lib/job.rb