Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

...
  • 3 commits
  • 9 files changed
  • 0 commit comments
  • 3 contributors
19 app/controllers/admin/jobs_controller.rb
View
@@ -0,0 +1,19 @@
+class Admin::JobsController < AdminController
+ layout false
+ def do
+ begin
+ jobtype = params[:job_type].camelcase.constantize
+ id = params[:id]
+ rescue Exception => e
+ render :text => "Did not understand parameters", :status => 500 and return
+ end
+
+ begin
+ jobtype.process(id)
+ render :text => "Job successful", :status => 200 and return
+ rescue Exception => e
+ render :text => "Job threw an error", :status => 500 and return
+ end
+
+ end
+end
5 app/models/event.rb
View
@@ -82,5 +82,10 @@ def self.create_from_zvent_event(zvent, user)
:url => "http://www.zvents.com/"+zvent.zurl)
end
end
+
+ def self.process(param)
+
+ end
+
end
19 config/initializers/load_queue.rb
View
@@ -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
1  config/routes.rb
View
@@ -71,6 +71,7 @@
map.root :controller => "home", :action => "index"
map.admin 'admin', :controller => :admin, :action => :index
map.namespace(:admin) do |admin|
+ admin.do_job '/jobs/do/:job_type/:id', :controller => 'jobs', :action => 'do'
admin.block '/block.:format', :controller => 'misc', :action => 'block'
admin.flag_item '/flag_item.:format', :controller => 'misc', :action => 'flag'
admin.feature '/feature.:format', :controller => 'misc', :action => 'feature'
26 lib/jobs/noqueue.rb
View
@@ -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
21 lib/jobs/resque.rb
View
@@ -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
30 lib/jobs/workers/noqueue.rb
View
@@ -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
34 lib/jobs/workers/resque.rb
View
@@ -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
16 lib/tasks/jobs.rake
View
@@ -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

No commit comments for this range

Something went wrong with that request. Please try again.