Skip to content

Commit

Permalink
mount sidekiq dashboard (publiclab#2772)
Browse files Browse the repository at this point in the history
* changes in docker-compose.yml for redis fixes

* minor chnanges

* minor tweak

* add redis url to web container

* minor chane for testing

* minor chane for testing

* merge with master

* changes in tests

* Fix link to redis container

* Fix directory reference for sidekiq volume

* Fix circular dependency.

* Add link to redis container to testing compose file

* remove sidekiq admin constraints for testing

* sample cron job for testing on unstable

* changes for testing

* minor changes

* mysql connection fix

* mysql connection fix 2

* mysql connection fix 3

* mysql connection fix 4

* Try link to db.

* Add rails environment

* Update users_controller_test.rb

* minor chane for testing

* merge with master

* Fix circular dependency.

* Add link to redis container to testing compose file

* made docker-compose changes for production

* minor change
  • Loading branch information
ViditChitkara authored and jywarren committed Jul 3, 2018
1 parent 6843e2f commit b6b6c38
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ def followers
end

def test_digest_email
DigestMailJob.perform_later
redirect_to "/profile/"+current_user.username
DigestMailJob.perform_async
redirect_to "/"
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/jobs/digest_mail_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class DigestMailJob < ActiveJob::Base
queue_as :default
class DigestMailJob
include Sidekiq::Worker
# This is a separate job for sending digest mails.This job could be enqueued for executing task asynchronously.
def perform
users = User.includes(:user_tags).references(:user_tags).where('user_tags.value=?', 'digest:weekly').all
Expand Down
14 changes: 13 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,19 @@ def social_link(site)
def send_digest_email
top_picks = self.content_followed_in_period(Time.now - 1.week, Time.now)
if top_picks.count > 0
SubscriptionMailer.send_digest(self.id,top_picks).deliver_now
SubscriptionMailer.send_digest(self.id, top_picks).deliver_now
end
end

def customize_digest(type)
if type==0
newtag = 'digest:daily'
elsif type==1
newtag = 'digest:weekly'
end
unless newtag.blank?
UserTag.where('value LIKE (?)','digest%').destroy_all
UserTag.create(uid: self.id, value: newtag)
end
end

Expand Down
4 changes: 3 additions & 1 deletion app/views/users/profile.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@
<% end %>

<% if @profile_user && current_user && @profile_user == current_user %>
<a href="/users/test_digest_email" class="btn btn-default btn-sm btn-block" data-method="post">Test Digest Email</a>
<%= form_tag "/users/test_digest_email", method: :post do %>
<%= submit_tag "Test Digest Email" %>
<% end %>
<% end %>

<hr />
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sidekiq_config = { url: ENV['JOB_WORKER_URL'] }
sidekiq_config = { url: ENV['REDIS_URL'] }

Sidekiq.configure_server do |config|
config.redis = sidekiq_config
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
require 'sidekiq/web'

Plots2::Application.routes.draw do
mount JasmineRails::Engine => '/specs' if defined?(JasmineRails)
mount JasmineFixtureServer => '/spec/javascripts/fixtures' if defined?(Jasmine::Jquery::Rails::Engine)

mount Sidekiq::Web => '/sidekiq'

# Manually written API functions
post 'comment/create/token/:id.:format', to: 'comment#create_by_token'

Expand Down
4 changes: 4 additions & 0 deletions config/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@
puts Dir.pwd
command "date -u" #This will print utc time every 1 min in log/cron_log.log file
end

every 1.week do
runner "DigestMailJob.perform_async"
end
16 changes: 16 additions & 0 deletions containers/docker-compose-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ services:
- /etc/passwd:/etc/passwd:ro
- /etc/group:/etc/group:ro
restart: unless-stopped
redis:
image: redis:latest
ports:
- '127.0.0.1:6379:6379'
command: redis-server
sidekiq:
build: ..
command: bundle exec sidekiq -L log/sidekiq.log
depends_on:
- redis
network_mode: "host"
volumes:
- .:/app
environment:
- RAILS_ENV=${RAILS_ENV}
- REDIS_URL=redis://redis:6379/0
mailman:
build: ..
network_mode: "host"
Expand Down
24 changes: 23 additions & 1 deletion containers/docker-compose-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: "2"
services:
db:
image: mariadb:10.2
network_mode: "service:web"
environment:
- MYSQL_DATABASE=plots
- MYSQL_USER=plots
Expand All @@ -13,8 +14,13 @@ services:
- ../../mysql:/var/lib/mysql
# for persistence
- ../../dump:/docker-entrypoint-initdb.d
# mporting a dump
# for importing a dump
# if you want to re-import simply put away ../../mysql/*
redis:
image: redis:latest
ports:
- '6379:6379'
command: redis-server
web:
build: ..
command: /bin/bash -c "sleep 5 && /usr/local/bundle/bin/passenger start -p 4000"
Expand All @@ -32,13 +38,29 @@ services:
- OAUTH_TWITTER_APP_SECRET=${OAUTH_TWITTER_APP_SECRET}
- OAUTH_FACEBOOK_APP_KEY=${OAUTH_FACEBOOK_APP_KEY}
- OAUTH_FACEBOOK_APP_SECRET=${OAUTH_FACEBOOK_APP_SECRET}
- REDIS_URL=redis://redis:6379/0
volumes:
- ..:/app
ports:
- "127.0.0.1:4000:4000"
links:
- redis
- db
restart: unless-stopped
sidekiq:
build: ..
command: bundle exec sidekiq -L log/sidekiq.log
depends_on:
- db
- redis
links:
- db
- redis
volumes:
- .:/app
environment:
- RAILS_ENV=${RAILS_ENV}
- REDIS_URL=redis://redis:6379/0
mailman:
build: ..
command: script/mailman_server
Expand Down
11 changes: 10 additions & 1 deletion containers/docker-compose-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ services:
# if you want to re-import simply put away ../../mysql/*
redis:
image: redis:latest
ports:
- '6379:6379'
command: redis-server
web:
build: ..
command: /bin/bash -c "sleep 5 && passenger start -p 4000"
environment:
- RAILS_ENV=${RAILS_ENV}
- SECRET_KEY_BASE=${SECRET_KEY_BASE}
- REDIS_URL=redis://redis:6379/0
links:
- redis
volumes:
- ..:/app
ports:
Expand All @@ -35,7 +41,10 @@ services:
depends_on:
- db
- redis
links:
- db
- redis
volumes:
- .:/app
environment:
- JOB_WORKER_URL=redis://redis:6379/0
- REDIS_URL=redis://redis:6379/0
23 changes: 22 additions & 1 deletion containers/docker-compose-unstable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ services:
- MYSQL_RANDOM_ROOT_PASSWORD=true
volumes:
- ../config/my.cnf:/etc/mysql/my.cnf
# for configuration
# for configuration
- ../../mysql:/var/lib/mysql
# for persistence
- ../../dump:/docker-entrypoint-initdb.d
# for importing a dump
# if you want to re-import simply put away ../../mysql/*
redis:
image: redis:latest
ports:
- '6379:6379'
command: redis-server
web:
build: ..
command: /bin/bash -c "sleep 5 && bundle exec rails s -p 5001 -b '0.0.0.0'"
Expand All @@ -32,12 +37,14 @@ services:
- OAUTH_TWITTER_APP_SECRET=${OAUTH_TWITTER_APP_SECRET}
- OAUTH_FACEBOOK_APP_KEY=${OAUTH_FACEBOOK_APP_KEY}
- OAUTH_FACEBOOK_APP_SECRET=${OAUTH_FACEBOOK_APP_SECRET}
- REDIS_URL=redis://redis:6379/0
volumes:
- ..:/app
ports:
- "127.0.0.1:5001:5001"
links:
- db
- redis
restart: unless-stopped
mailman:
build: ..
Expand All @@ -49,3 +56,17 @@ services:
- EMAIL_PASSWORD=${EMAIL_PASSWORD}
volumes:
- ..:/app
sidekiq:
build: ..
command: bundle exec sidekiq -L log/sidekiq.log
depends_on:
- db
- redis
links:
- db
- redis
volumes:
- .:/app
environment:
- RAILS_ENV=${RAILS_ENV}
- REDIS_URL=redis://redis:6379/0
7 changes: 7 additions & 0 deletions lib/admin_constraint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AdminConstraint
def matches?(request)
return false unless request.session[:user_credentials_id]
user = User.find request.session[:user_credentials_id]
user && user.admin?
end
end
5 changes: 1 addition & 4 deletions test/functional/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,6 @@ def setup
user = users(:bob)
UserSession.create(user)
post :test_digest_email
assert_enqueued_with(job: DigestMailJob) do
DigestMailJob.perform_later
end
assert_enqueued_jobs 2
assert_redirected_to '/'
end
end

0 comments on commit b6b6c38

Please sign in to comment.