governor_background 0.1.0 → 0.2.0

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ./
3
3
  specs:
4
- governor_background (0.1.0)
4
+ governor_background (0.2.0)
5
5
  governor
6
6
 
7
7
  GEM
@@ -115,7 +115,7 @@ GEM
115
115
  rspec-core (~> 2.5.0)
116
116
  rspec-expectations (~> 2.5.0)
117
117
  rspec-mocks (~> 2.5.0)
118
- rspec-core (2.5.1)
118
+ rspec-core (2.5.2)
119
119
  rspec-expectations (2.5.0)
120
120
  diff-lcs (~> 1.1.2)
121
121
  rspec-mocks (2.5.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{governor_background}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Liam Morley"]
12
- s.date = %q{2011-04-24}
12
+ s.date = %q{2011-05-12}
13
13
  s.description = %q{A middle-tier plugin for the Rails 3-based Governor blogging system, allowing you to tie in additional services that might want to perform blog-related services in the background.}
14
14
  s.email = %q{liam@carpeliam.com}
15
15
  s.extra_rdoc_files = [
@@ -9,7 +9,7 @@ module GovernorBackground
9
9
  finished_jobs = GovernorBackground::JobManager.finished_jobs
10
10
  unless finished_jobs.blank?
11
11
  flash[:governor_background] = finished_jobs.map do |job|
12
- [job.status, t("#{job.method_name}_#{job.status}", :resource => job.resource, :message => job.message, :scope => :governor_background)]
12
+ [job.status, t("#{job.method_name}_#{job.status}", :resource => job.resource, :message => job.message, :default => [job.status, job.status.to_sym], :scope => :governor_background)]
13
13
  end
14
14
  end
15
15
  end
@@ -1,8 +1,12 @@
1
1
  module GovernorBackground
2
2
  module Delayed
3
- class Performer < Struct.new(:article, :method_name)
3
+ class Performer < Struct.new(:article, :method_name, :arguments)
4
4
  def perform
5
- article.send(method_name)
5
+ if arguments.blank?
6
+ article.send(method_name)
7
+ else
8
+ article.send(method_name, *arguments)
9
+ end
6
10
  end
7
11
 
8
12
  def error(job, exception)
@@ -1,16 +1,16 @@
1
1
  module GovernorBackground
2
2
  class Handler
3
3
  class << self
4
- def run_in_background(object, method)
4
+ def run_in_background(object, method, arguments=[])
5
5
  job = if delayed_job?
6
- Delayed::Job.new(object, method, ::Delayed::Job.enqueue(Delayed::Performer.new(object, method)))
6
+ Delayed::Job.new(object, method, ::Delayed::Job.enqueue(Delayed::Performer.new(object, method, arguments)))
7
7
  elsif resque?
8
8
  resource_key, id = object.class.name.tableize.to_sym, object.id
9
9
  if resque_with_status?
10
10
  require File.expand_path('../resque/performer_with_state', __FILE__)
11
- Resque::Job.new(object, method, Resque::PerformerWithState.create(:resource => resource_key, :id => id, :method_name => method))
11
+ Resque::Job.new(object, method, Resque::PerformerWithState.create(:resource => resource_key, :id => id, :method_name => method, :arguments => arguments))
12
12
  else
13
- ::Resque.enqueue(Resque::Performer, resource_key, id, method)
13
+ ::Resque.enqueue(Resque::Performer, resource_key, id, method, arguments)
14
14
  nil # not much use in holding on to state if we can't track it
15
15
  end
16
16
  end
@@ -3,9 +3,13 @@ module GovernorBackground
3
3
  class Performer
4
4
  @queue = :governor
5
5
 
6
- def self.perform(resource, id, method_name)
6
+ def self.perform(resource, id, method_name, arguments=[])
7
7
  article = Governor.resources[resource].to.find(id)
8
- article.send(method_name)
8
+ if arguments.blank?
9
+ article.send(method_name)
10
+ else
11
+ article.send(method_name, arguments)
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -10,7 +10,11 @@ module GovernorBackground
10
10
  id = options['id']
11
11
  method_name = options['method_name']
12
12
  article = Governor.resources[resource].to.find(id)
13
- article.send(method_name)
13
+ if options.has_key?('arguments') && options['arguments'].present?
14
+ article.send(method_name, arguments)
15
+ else
16
+ article.send(method_name)
17
+ end
14
18
  end
15
19
  end
16
20
  end
@@ -12,8 +12,8 @@ background = Governor::Plugin.new('background')
12
12
  background.register_model_callback do |base|
13
13
  module InstanceMethods
14
14
  private
15
- def run_in_background(method)
16
- GovernorBackground::Handler.run_in_background self, method
15
+ def run_in_background(method, arguments=[])
16
+ GovernorBackground::Handler.run_in_background self, method, arguments
17
17
  end
18
18
  end
19
19
  base.send :include, InstanceMethods
@@ -40,7 +40,7 @@ module GovernorBackground
40
40
  Handler.use_resque = true
41
41
  Handler.run_in_background(@article, :post)
42
42
  id = JobManager.jobs.first.id
43
- Resque::PerformerWithState.should have_queued(id, {:resource => :articles, :id => @article.id, :method_name => :post}).in(:governor)
43
+ Resque::PerformerWithState.should have_queued(id, {:resource => :articles, :id => @article.id, :method_name => :post, :arguments => []}).in(:governor)
44
44
  end
45
45
  end
46
46
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- governor_background (0.0.0)
4
+ governor_background (0.2.0)
5
5
  governor
6
6
 
7
7
  GEM
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: governor_background
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Liam Morley
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-24 00:00:00 -04:00
18
+ date: 2011-05-12 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency