Skip to content

Commit

Permalink
WIP: 別コンテナで別プロセスとしてSidekiqを動かすことに成功した
Browse files Browse the repository at this point in the history
  • Loading branch information
kakeru-one committed Oct 15, 2024
1 parent a735600 commit d07ca80
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend/app/controllers/memos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class MemosController < ApplicationController
# GET /memos
def index
memos = Memo.order(id: 'DESC')
HardWorker.perform_async('テストで非同期処理します', 1)
HardWorker.perform_in(3.hours, 'Classmethod', 1)
render json: { memos: memos }, status: :ok
end

Expand Down
9 changes: 9 additions & 0 deletions backend/app/workers/hard_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class HardWorker
include Sidekiq::Worker

def perform(name, count)
puts 'Doing hard work: name=' + name + ', count=' + count.to_s
end
end
7 changes: 7 additions & 0 deletions backend/config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Sidekiq.configure_server do |config|
config.redis = { url: 'redis://sns-archive-viewer_redis:6379/0' }
end

Sidekiq.configure_client do |config|
config.redis = { url: 'redis://sns-archive-viewer_redis:6379/0' }
end
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ services:
interval: 5s
timeout: 10s
retries: 5
sidekiq:
container_name: sns-archive-viewer_sidekiq
build:
context: .
dockerfile: ./infra/backend/Dockerfile
command: bundle exec sidekiq
volumes:
- ./backend:/usr/src/app
depends_on:
- redis
- backend
redis:
container_name: sns-archive-viewer_redis
image: redis:7.0
Expand Down

0 comments on commit d07ca80

Please sign in to comment.