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.
- Loading branch information
Showing
7 changed files
with
123 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require 'forwardable' | ||
require 'securerandom' | ||
|
||
module Qu | ||
module Backend | ||
class Memory < Base | ||
extend Forwardable | ||
|
||
def_delegator :@monitor, :synchronize | ||
|
||
def initialize | ||
@monitor = Monitor.new | ||
@queues = {} | ||
@pending = {} | ||
end | ||
|
||
def push(payload) | ||
synchronize do | ||
payload.id = SecureRandom.uuid | ||
queue_for(payload.queue) << payload | ||
end | ||
end | ||
|
||
def complete(payload) | ||
synchronize { @pending.delete(payload.id) } | ||
end | ||
|
||
def abort(payload) | ||
synchronize do | ||
@pending.delete(payload.id) | ||
push(payload) | ||
end | ||
end | ||
|
||
alias fail abort | ||
|
||
def pop(queue = 'default') | ||
synchronize do | ||
queue_for(queue).shift | ||
end | ||
end | ||
|
||
def size(queue = 'default') | ||
queue_for(queue).size | ||
end | ||
|
||
def clear(queue = 'default') | ||
synchronize { queue_for(queue).clear } | ||
end | ||
|
||
private | ||
|
||
def queue_for(queue) | ||
synchronize { @queues[queue] ||= [] } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Qu | ||
module Runner | ||
class Direct | ||
|
||
def run( payload ) | ||
payload.perform | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Qu | ||
module Runner | ||
class Threaded | ||
|
||
attr_reader :thread_count | ||
|
||
def initialize( options = {} ) | ||
@thread_count = options[:threads] || 1 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'spec_helper' | ||
require 'qu/backend/memory' | ||
|
||
describe Qu::Backend::Memory do | ||
it_should_behave_like 'a backend' | ||
it_should_behave_like 'a backend interface' | ||
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,18 @@ | ||
class MessageQueue | ||
|
||
end | ||
|
||
class PriorityJob < Qu::Job | ||
queue :priority | ||
|
||
def initialize( message ) | ||
@message | ||
end | ||
|
||
|
||
|
||
end | ||
|
||
class NonPriorityJob < Qu::Job | ||
queue :not_priority | ||
end |