Skip to content

Commit 966d050

Browse files
authored
Merge pull request #8 from Bulletdev/PS006
feat: implement complete authentication improvements
2 parents 604f6c5 + 70ad0f7 commit 966d050

28 files changed

Lines changed: 1090 additions & 73 deletions

.env.example

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@ SMTP_PORT=587
4747
SMTP_USERNAME=your_email@gmail.com
4848
SMTP_PASSWORD=your_app_password
4949
SMTP_DOMAIN=gmail.com
50+
SMTP_AUTHENTICATION=plain
51+
SMTP_ENABLE_STARTTLS_AUTO=true
5052

51-
# Frontend URL (for email links)
53+
# Mailer Settings
54+
MAILER_FROM_EMAIL=noreply@prostaff.gg
55+
MAILER_DELIVERY_METHOD=smtp
56+
57+
# Frontend URL (for email links and password reset)
5258
FRONTEND_URL=http://localhost:8888
5359

5460
# ===========================================

DOCS/QUICK_START_SIDEKIQ.md

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# Quick Start: Sidekiq Scheduler
2+
3+
Guia rápido para iniciar o Sidekiq com agendamento de jobs.
4+
5+
## Pré-requisitos
6+
7+
- Redis instalado e rodando
8+
- Gems instaladas (`bundle install`)
9+
10+
## Iniciar em Desenvolvimento
11+
12+
### 1. Verifique o Redis
13+
14+
```bash
15+
redis-cli ping
16+
# Deve retornar: PONG
17+
```
18+
19+
Se o Redis não estiver rodando:
20+
21+
```bash
22+
# Linux/Mac
23+
redis-server
24+
25+
# Com Docker
26+
docker run -d -p 6379:6379 redis:alpine
27+
```
28+
29+
### 2. Inicie o Sidekiq
30+
31+
Em um terminal separado:
32+
33+
```bash
34+
bundle exec sidekiq
35+
```
36+
37+
Você deverá ver:
38+
39+
```
40+
_ _
41+
(_)(_)
42+
___ _ _ __| | ___| | __(_) __ _
43+
/ __|| |/ _` |/ _ \ |/ / |/ _` |
44+
\__ \| | (_| | __/ <| | (_| |
45+
|___/|_|\__,_|\___|_|\_\_|\__, |
46+
|_|
47+
48+
📅 Schedule loaded:
49+
- cleanup_expired_tokens (daily at 2:00 AM)
50+
```
51+
52+
### 3. Verificar Job Agendado
53+
54+
No console Rails:
55+
56+
```ruby
57+
rails console
58+
59+
# Ver schedule
60+
Sidekiq.schedule
61+
# => {"cleanup_expired_tokens"=>{"cron"=>"0 2 * * *", "class"=>"CleanupExpiredTokensJob", ...}}
62+
63+
# Ver próxima execução
64+
SidekiqScheduler::Scheduler.instance.rufus_scheduler.jobs.each do |job|
65+
puts "#{job.tags.first}: next run at #{job.next_time}"
66+
end
67+
```
68+
69+
### 4. Testar Job Manualmente
70+
71+
```ruby
72+
# No console Rails
73+
CleanupExpiredTokensJob.perform_now
74+
# => Executa imediatamente
75+
76+
# Ou em background
77+
CleanupExpiredTokensJob.perform_later
78+
# => Enfileira para execução
79+
```
80+
81+
## Verificar Status
82+
83+
### Via Console
84+
85+
```ruby
86+
# Ver jobs na fila
87+
Sidekiq::Queue.all.each do |queue|
88+
puts "#{queue.name}: #{queue.size} jobs"
89+
end
90+
91+
# Ver workers ativos
92+
Sidekiq::Workers.new.size
93+
94+
# Ver estatísticas
95+
stats = Sidekiq::Stats.new
96+
puts "Processed: #{stats.processed}"
97+
puts "Failed: #{stats.failed}"
98+
puts "Enqueued: #{stats.enqueued}"
99+
```
100+
101+
### Via Web UI (Opcional)
102+
103+
Adicione ao `config/routes.rb`:
104+
105+
```ruby
106+
require 'sidekiq/web'
107+
require 'sidekiq-scheduler/web'
108+
109+
mount Sidekiq::Web => '/sidekiq'
110+
```
111+
112+
Acesse: http://localhost:3333/sidekiq
113+
114+
## Logs
115+
116+
```bash
117+
# Ver logs do Sidekiq
118+
tail -f log/sidekiq.log
119+
120+
# Ver logs do Rails
121+
tail -f log/development.log
122+
```
123+
124+
## Parar o Sidekiq
125+
126+
```bash
127+
# Graceful shutdown (aguarda jobs terminarem)
128+
Ctrl+C
129+
130+
# Force shutdown
131+
Ctrl+C (duas vezes)
132+
```
133+
134+
## Troubleshooting
135+
136+
### Redis não conecta
137+
138+
```bash
139+
# Verifique a URL do Redis
140+
echo $REDIS_URL
141+
# Se vazio, use: redis://localhost:6379/0
142+
143+
# Teste a conexão
144+
redis-cli -u redis://localhost:6379/0 ping
145+
```
146+
147+
### Schedule não carrega
148+
149+
```bash
150+
# Verifique o arquivo de configuração
151+
cat config/sidekiq.yml
152+
153+
# Teste o carregamento manual
154+
bundle exec rails runner "pp YAML.load_file('config/sidekiq.yml')[:schedule]"
155+
```
156+
157+
### Jobs não executam
158+
159+
1. Certifique-se de que o Sidekiq está rodando
160+
2. Verifique os logs: `tail -f log/sidekiq.log`
161+
3. Teste manualmente: `CleanupExpiredTokensJob.perform_now`
162+
163+
## Próximos Passos
164+
165+
- Leia a documentação completa: `DOCS/SIDEKIQ_SCHEDULER_GUIDE.md`
166+
- Configure jobs adicionais em `config/sidekiq.yml`
167+
- Adicione monitoramento com Web UI
168+
- Configure systemd/supervisor para produção
169+
170+
## Jobs Configurados
171+
172+
### CleanupExpiredTokensJob
173+
174+
- **Frequência**: Diariamente às 2:00 AM
175+
- **Função**: Limpa tokens expirados (password reset e JWT blacklist)
176+
- **Execução manual**: `CleanupExpiredTokensJob.perform_now`
177+
178+
---
179+
180+
Pronto! Seu Sidekiq com agendamento está configurado e rodando! 🚀

0 commit comments

Comments
 (0)