Skip to content
Browse files

Initial base job queue classes

  • Loading branch information...
1 parent 4665b61 commit 1c1877e920c58424d883eb7bb3163a454a81c0c3 Russell committed May 25, 2010
View
19 config/initializers/load_queue.rb
@@ -0,0 +1,19 @@
+queue = APP_CONFIG['jobqueue'] || 'noqueue'
+
+if queue and File.exists?("#{RAILS_ROOT}/lib/jobs/#{queue.downcase}.rb")
+ require "#{RAILS_ROOT}/lib/jobs/#{queue.downcase}"
+
+ jobqueue = N2::JobQueues.const_get(queue.camelize).const_get('Job')
+
+ Rails.class_eval do
+ @@jobqueue = nil
+ #cattr_reader :jobqueue
+ class << self; attr_accessor :jobqueue; end
+
+ #def self.jobqueue=(jobqueue)
+ #@@jobqueue = jobqueue
+ #end
+ end
+
+ Rails.jobqueue = jobqueue
+end
View
0 lib/jobqueue.rb
No changes.
View
26 lib/jobs/noqueue.rb
@@ -0,0 +1,26 @@
+require 'lib/jobs/workers/noqueue'
+
+module N2
+ module JobQueues
+
+ module Noqueue
+
+ class Job
+
+ def self.enqueue klass, params
+ klass.send(:perform, params)
+ end
+
+ def self.dequeue klass, params
+ end
+
+ def self.workers
+ N2::JobQueues::Noqueue::Workers
+ end
+
+ end
+
+ end
+
+ end
+end
View
21 lib/jobs/resque.rb
@@ -0,0 +1,21 @@
+require 'resque'
+
+module N2
+ module JobQueues
+
+ module Resque
+ class Job
+
+ def self.enqueue klass, params
+ Resque.enqueue klass, params
+ end
+
+ def self.dequeue klass, params
+ Resque.dequeue klass, params
+ end
+
+ end
+ end
+
+ end
+end
View
30 lib/jobs/workers/noqueue.rb
@@ -0,0 +1,30 @@
+module N2
+ module JobQueues
+
+ module Noqueue
+ module Workers
+
+ module RakeJob
+ @queue = :rake_tasks
+
+ def self.perform(command)
+ # TODO:: make this work with params
+ Rake::Task[command].invoke
+ end
+ end
+
+ module ImageJob
+ @queue = :image_processing
+
+ def self.perform(url, pid = nil, socket = nil)
+ # bump unicorn worker count if pid
+ # curl url to socket if socket
+ # drop unicorn worker count if pid
+ end
+ end
+
+ end
+ end
+
+ end
+end
View
34 lib/jobs/workers/resque.rb
@@ -0,0 +1,34 @@
+require 'open3'
+
+module N2
+ module JobQueues
+
+ module Resque
+ module Workers
+
+ module RakeJob
+ @queue = :rake_tasks
+
+ def self.perform(path, command)
+ Open3.popen(%{cd #{path} && #{command}}) do |stdin, stdout, stderr|
+ raise stderr and return if stderr
+ puts stdout.get
+ end
+ end
+ end
+
+ module ImageJob
+ @queue = :image_processing
+
+ def self.perform(url, pid = nil, socket = nil)
+ # bump unicorn worker count if pid
+ # curl url to socket if socket
+ # drop unicorn worker count if pid
+ end
+ end
+
+ end
+ end
+
+ end
+end
View
16 lib/tasks/jobs.rake
@@ -0,0 +1,16 @@
+require 'lib/jobs/noqueue'
+
+namespace :n2 do
+ namespace :jobs do
+ desc "Run job"
+ task :run do
+ @queue = N2::JobQueues::Noqueue::Job
+
+ @queue.enqueue @queue.workers::RakeJob, 'n2:jobs:test'
+ end
+
+ task :test do
+ puts "test rake task!!"
+ end
+ end
+end

0 comments on commit 1c1877e

Please sign in to comment.
Something went wrong with that request. Please try again.