forked from bkeepers/qu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create separate class to execute jobs
This is a proposal for bkeepers#5. Creates a separate class to execute the job instead of doing the execution inside the worker. This allows us to have different execution mechanisms, from the current "just run", to a forking runner and in the future other threaded runners (that would be better suited for JRuby and Rubinius).
- Loading branch information
Showing
28 changed files
with
515 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,10 @@ def size(queue = 'default') | |
|
||
def clear(queue = 'default') | ||
end | ||
|
||
def reconnect | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,9 @@ def connection | |
@connection ||= ::AWS::SQS.new | ||
end | ||
|
||
def reconnect | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Qu | ||
module Runner | ||
RunnerLimitReached = Class.new(StandardError) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'qu/runner/base' | ||
require 'qu/util/signal_handler' | ||
require 'qu/util/thread_safe_hash' | ||
require 'qu/util/process_wrapper' | ||
|
||
module Qu | ||
module Runner | ||
|
||
class Forking | ||
|
||
attr_reader :fork_limit, :forks | ||
|
||
def initialize( fork_limit = 1 ) | ||
@fork_limit = fork_limit | ||
@forks = Qu::Util::ThreadSafeHash.new | ||
end | ||
|
||
def full? | ||
forks.size == fork_limit | ||
end | ||
|
||
def run(worker, payload) | ||
raise RunnerLimitReached.new("#{self.class.name} is already running #{fork_limit} jobs") if full? | ||
|
||
process = Qu::Util::ProcessWrapper.new( forks, worker, payload ) | ||
process.fork | ||
end | ||
|
||
def stop | ||
forks.values.each do |process| | ||
process.stop | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.