Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mount sidekiq dashboard #2772

Merged
merged 30 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
027d32a
changes in docker-compose.yml for redis fixes
ViditChitkara Jun 7, 2018
80ba151
minor chnanges
ViditChitkara Jun 7, 2018
3604717
minor tweak
ViditChitkara Jun 7, 2018
fa9cf21
add redis url to web container
ViditChitkara Jun 8, 2018
8e4309c
minor chane for testing
ViditChitkara Jun 8, 2018
5638229
minor chane for testing
ViditChitkara Jun 8, 2018
bd78f73
merge with master
ViditChitkara Jun 25, 2018
417615d
changes in tests
ViditChitkara Jun 25, 2018
ab04771
Fix link to redis container
icarito Jun 27, 2018
4c71ae2
Fix directory reference for sidekiq volume
icarito Jun 27, 2018
1086003
Fix circular dependency.
icarito Jun 27, 2018
946d73f
Add link to redis container to testing compose file
icarito Jun 27, 2018
670cb47
remove sidekiq admin constraints for testing
ViditChitkara Jun 27, 2018
4822f18
sample cron job for testing on unstable
ViditChitkara Jun 27, 2018
ae39432
changes for testing
ViditChitkara Jun 27, 2018
651556f
minor changes
ViditChitkara Jun 27, 2018
93e6034
mysql connection fix
ViditChitkara Jun 27, 2018
95c4b50
mysql connection fix 2
ViditChitkara Jun 27, 2018
7fb3660
mysql connection fix 3
ViditChitkara Jun 27, 2018
2537874
mysql connection fix 4
ViditChitkara Jun 27, 2018
dc70a27
Try link to db.
icarito Jun 29, 2018
7298c51
Add rails environment
icarito Jun 29, 2018
17b53c7
Update users_controller_test.rb
jywarren Jun 29, 2018
4f556bd
minor chane for testing
ViditChitkara Jun 8, 2018
3894f07
merge with master
ViditChitkara Jun 25, 2018
6f230c1
Fix circular dependency.
icarito Jun 27, 2018
03aa3f1
Add link to redis container to testing compose file
icarito Jun 27, 2018
027bd44
made docker-compose changes for production
ViditChitkara Jun 30, 2018
55b7018
minor change
ViditChitkara Jun 30, 2018
b3c9db8
Merge branch 'master' into sidekiq-config
jywarren Jul 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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