Skip to content

Commit

Permalink
Add resque and redis
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyMorugin committed Nov 10, 2015
1 parent e1a856b commit 3134b72
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 32 deletions.
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ gem 'net-ssh'

gem 'net-scp'

gem 'sidekiq'
#gem 'sidekiq'

gem 'resque'
#gem 'resue-scheduler'

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
Expand Down
44 changes: 16 additions & 28 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,37 +52,18 @@ GEM
activesupport (>= 3.2.0)
json (>= 1.7)
mime-types (>= 1.16)
celluloid (0.17.2)
celluloid-essentials
celluloid-extras
celluloid-fsm
celluloid-pool
celluloid-supervision
timers (>= 4.1.1)
celluloid-essentials (0.20.5)
timers (>= 4.1.1)
celluloid-extras (0.20.5)
timers (>= 4.1.1)
celluloid-fsm (0.20.5)
timers (>= 4.1.1)
celluloid-pool (0.20.5)
timers (>= 4.1.1)
celluloid-supervision (0.20.5)
timers (>= 4.1.1)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.9.1.1)
connection_pool (2.2.0)
debug_inspector (0.0.2)
erubis (2.7.0)
execjs (2.6.0)
globalid (0.3.6)
activesupport (>= 4.1.0)
hitimes (1.2.3)
i18n (0.7.0)
jbuilder (2.3.2)
activesupport (>= 3.0.0, < 5)
Expand All @@ -100,13 +81,16 @@ GEM
mini_magick (4.3.6)
mini_portile (0.6.2)
minitest (5.8.2)
mono_logger (1.1.0)
multi_json (1.11.2)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (3.0.1)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
rack (1.6.4)
rack-protection (1.5.3)
rack
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.4)
Expand Down Expand Up @@ -138,6 +122,12 @@ GEM
redis (3.2.1)
redis-namespace (1.5.2)
redis (~> 3.0, >= 3.0.4)
resque (1.25.2)
mono_logger (~> 1.0)
multi_json (~> 1.0)
redis-namespace (~> 1.3)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
sass (3.4.19)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
Expand All @@ -148,12 +138,10 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
sidekiq (3.5.3)
celluloid (~> 0.17.2)
connection_pool (~> 2.2, >= 2.2.0)
json (~> 1.0)
redis (~> 3.2, >= 3.2.1)
redis-namespace (~> 1.5, >= 1.5.2)
sinatra (1.4.6)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
spring (1.4.0)
sprockets (3.4.0)
rack (> 1, < 3)
Expand All @@ -165,15 +153,15 @@ GEM
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.1)
timers (4.1.1)
hitimes
turbolinks (2.5.3)
coffee-rails
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (2.7.2)
execjs (>= 0.3.0)
json (>= 1.8.0)
vegas (0.1.11)
rack (>= 1.0.0)
web-console (2.2.1)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
Expand All @@ -194,9 +182,9 @@ DEPENDENCIES
net-scp
net-ssh
rails (= 4.2.4)
resque
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
sidekiq
spring
sqlite3
turbolinks
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ def home
end

def about
ProcessImageJob.perform_later "asd"
Resque.enqueue(ImageJob)
#ProcessImageJob.perform_later "asd"
end

def error
Expand Down
40 changes: 40 additions & 0 deletions app/jobs/image_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'net/ssh'
require 'net/scp'
class ImageJob
@queue = :simple

def self.perform
# здесь делаем важные и полезные вещи
@hostname = "192.168.1.100"
@username = "margo"
@neural_path = "/home/margo/neural-style-master"
@password = "(ntvg123"

begin
# Sent task for image
Net::SSH.start(@hostname, @username, :password => @password) do |ssh|
output = ssh.exec!("hostname")
unless output.nil?
res = ssh.exec!("rm -rf #{@neural_path}/output/*")
ssh.open_channel do |c|
comm = "cd #{@neural_path} && export PATH=$PATH:/home/margo/torch/install/bin"
comm += " && th neural_style.lua -gpu -1 -image_size 50 -num_iterations 100"
comm += " -style_image input/template.jpg -content_image input/input.jpg -output_image output/out.png"
comm += " > output/output.log 2> output/error.log &"
c.exec(comm)
end
end
end
rescue
return "Unable to connect to start process"
end
begin
# Downloads files
Net::SCP.download!(@hostname, @username,"#{@neural_path}/output/out.png", "/home/matthew/RubymineProjects/ostagram/tmp/output/out.png", :ssh => { :password => @password })
rescue
return "Unable to connect to download result"
end
# sent mail
# puts "Job is done"
end
end
File renamed without changes.
3 changes: 2 additions & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# This file is used by Rack-based servers to start the application.

require 'resque/server'
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
run Rack::URLMap.new "/" => Ostagram::Application, "/resque" => Resque::Server.new
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

module Ostagram
class Application < Rails::Application
config.active_job.queue_adapter = :sidekiq
#config.active_job.queue_adapter = :sidekiq
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
Expand Down
4 changes: 4 additions & 0 deletions config/initializers/resque.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
uri = URI.parse("redis://localhost:6379/")
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)

Dir["#{Rails.root}/app/jobs/*.rb"].each { |file| require file }
2 changes: 2 additions & 0 deletions lib/tasks/resque.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'resque/tasks'
task "resque:setup" => :environment

0 comments on commit 3134b72

Please sign in to comment.