Skip to content

Commit 409e4b2

Browse files
committed
switch to falcon
1 parent 81bae3b commit 409e4b2

File tree

21 files changed

+340
-50
lines changed

21 files changed

+340
-50
lines changed

.circleci/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
name: request to start recording video
4747
command: |
4848
docker-compose -f .circleci/compose.yml exec rails curl chromevideo:9494/start
49+
4950
- run:
5051
name: run tests
5152
command: |
@@ -78,6 +79,7 @@ jobs:
7879
command: |
7980
sleep 3 # wait a bit for the video to finish being made
8081
docker-compose -f .circleci/compose.yml exec rails curl chromevideo:9494/stop
82+
8183
- run:
8284
name: download the video
8385
when: always
@@ -168,6 +170,7 @@ jobs:
168170
command: |
169171
sleep 3 # wait a bit for the video to finish being made
170172
docker-compose -f .circleci/compose-unit.yml exec rails-unit curl chromevideo:9494/stop
173+
171174
- run:
172175
name: download the video
173176
when: always

.rubocop.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ Layout/LineLength:
3737
Style/SignalException:
3838
Exclude:
3939
- 'Dangerfile'
40+
41+
# We don't want this
42+
Rails/ApplicationRecord:
43+
Exclude:
44+
- 'app/models/paper_trail/version.rb'

.rubocop_todo.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-05-26 05:10:14 UTC using RuboCop version 1.64.0.
3+
# on 2024-05-28 13:58:15 UTC using RuboCop version 1.64.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9+
# Offense count: 1
10+
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
11+
Metrics/AbcSize:
12+
Max: 26
13+
14+
# Offense count: 1
15+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
16+
Metrics/MethodLength:
17+
Max: 24
18+
919
# Offense count: 1
1020
# Configuration parameters: IgnoredMetadata.
1121
RSpec/DescribeClass:
1222
Exclude:
1323
- 'spec/browser/restricted_area_spec.rb'
1424

15-
# Offense count: 1
16-
# This cop supports unsafe autocorrection (--autocorrect-all).
17-
Rails/ApplicationRecord:
25+
# Offense count: 3
26+
# Configuration parameters: AllowedConstants.
27+
Style/Documentation:
1828
Exclude:
19-
- 'app/models/paper_trail/version.rb'
29+
- 'app/controllers/application_controller.rb'
30+
- 'app/controllers/websocket_controller.rb'

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ ADD --chown=srv:srv config /srv/config
3232
ADD --chown=srv:srv spec /srv/spec
3333
ADD --chown=srv:srv app /srv/app
3434

35+
RUN chown -R srv /srv && \
36+
chgrp -R srv /srv
37+
3538
USER srv
3639

3740
EXPOSE 3000
3841

3942
ENV RAILS_ENV=development
4043

41-
CMD ["sh", "-c", "rails s -b 0.0.0.0 -p 3000"]
44+
CMD ["sh", "-c", "rails s -u falcon -b 0.0.0.0 -p 3000"]

Gemfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
77
gem 'rails', '~> 7'
88
# Use postgresql as the database for Active Record
99
gem 'pg', '>= 0.18', '< 2.0'
10-
# Use Puma as the app server
11-
gem 'puma', '~> 6.3'
10+
# Use falcon as webserver
11+
gem 'falcon'
1212
# Use SCSS for stylesheets
1313
gem 'sass-rails', '~> 6.0'
1414
# Use Uglifier as compressor for JavaScript assets
@@ -50,15 +50,20 @@ gem 'ulid-rails', git: 'https://github.com/davidsiaw/ulid-rails'
5050
gem 'sidekiq'
5151
gem 'sidekiq-scheduler'
5252

53+
gem 'async-io'
54+
gem 'async-redis'
55+
gem 'async-websocket'
56+
gem 'thread-local'
57+
5358
group :development, :test do
5459
gem 'factory_bot_rails'
5560
gem 'pry-byebug', platforms: %i[mri mingw x64_mingw]
5661
gem 'rspec-rails'
5762
end
5863

5964
group :test do
60-
gem 'capybara'
6165
gem 'database_cleaner'
66+
gem 'falcon-capybara'
6267
gem 'rspec_junit_formatter'
6368
gem 'selenium-webdriver'
6469
gem 'shoulda-matchers'

Gemfile.lock

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,41 @@ GEM
9191
ar-uuid (0.2.3)
9292
activerecord
9393
ast (2.4.2)
94+
async (2.11.0)
95+
console (~> 1.25, >= 1.25.2)
96+
fiber-annotation
97+
io-event (~> 1.5, >= 1.5.1)
98+
timers (~> 4.1)
99+
async-container (0.18.2)
100+
async (~> 2.10)
101+
async-http (0.66.3)
102+
async (>= 2.10.2)
103+
async-pool (>= 0.6.1)
104+
io-endpoint (~> 0.10, >= 0.10.3)
105+
io-stream (~> 0.4)
106+
protocol-http (~> 0.26.0)
107+
protocol-http1 (~> 0.19.0)
108+
protocol-http2 (~> 0.17.0)
109+
traces (>= 0.10.0)
110+
async-http-cache (0.4.3)
111+
async-http (~> 0.56)
112+
async-io (1.43.2)
113+
async
114+
async-pool (0.6.1)
115+
async (>= 1.25)
116+
async-redis (0.8.1)
117+
async (>= 1.8, < 3.0)
118+
async-pool (~> 0.2)
119+
io-endpoint (~> 0.10)
120+
io-stream (~> 0.4)
121+
protocol-redis (~> 0.8.0)
122+
async-service (0.12.0)
123+
async
124+
async-container (~> 0.16)
125+
async-websocket (0.26.1)
126+
async-http (~> 0.54)
127+
protocol-rack (~> 0.5)
128+
protocol-websocket (~> 0.11)
94129
base32-crockford (0.1.0)
95130
base64 (0.2.0)
96131
bcrypt (3.1.20)
@@ -123,6 +158,10 @@ GEM
123158
colored2 (3.1.2)
124159
concurrent-ruby (1.3.1)
125160
connection_pool (2.4.1)
161+
console (1.25.2)
162+
fiber-annotation
163+
fiber-local (~> 1.1)
164+
json
126165
cork (0.3.0)
127166
colored2 (~> 3.1)
128167
crass (1.0.6)
@@ -181,6 +220,22 @@ GEM
181220
railties (>= 5.0.0)
182221
faker (3.4.1)
183222
i18n (>= 1.8.11, < 2)
223+
falcon (0.47.6)
224+
async
225+
async-container (~> 0.18)
226+
async-http (~> 0.66, >= 0.66.3)
227+
async-http-cache (~> 0.4.0)
228+
async-service (~> 0.10)
229+
bundler
230+
localhost (~> 1.1)
231+
openssl (~> 3.0)
232+
process-metrics (~> 0.2.0)
233+
protocol-rack (~> 0.5)
234+
samovar (~> 2.3)
235+
falcon-capybara (1.6.1)
236+
capybara (~> 3.37)
237+
falcon
238+
selenium-webdriver
184239
faraday (2.9.0)
185240
faraday-net_http (>= 2.0, < 3.2)
186241
faraday-http-cache (2.5.1)
@@ -191,6 +246,10 @@ GEM
191246
faraday (~> 2.0)
192247
ffaker (2.23.0)
193248
ffi (1.16.3)
249+
fiber-annotation (0.2.0)
250+
fiber-local (1.1.0)
251+
fiber-storage
252+
fiber-storage (0.1.1)
194253
fugit (1.11.0)
195254
et-orbi (~> 1, >= 1.2.11)
196255
raabro (~> 1.4)
@@ -223,6 +282,9 @@ GEM
223282
i18n (1.14.5)
224283
concurrent-ruby (~> 1.0)
225284
io-console (0.7.2)
285+
io-endpoint (0.10.3)
286+
io-event (1.5.1)
287+
io-stream (0.4.0)
226288
irb (1.13.1)
227289
rdoc (>= 4.0.0)
228290
reline (>= 0.4.2)
@@ -238,6 +300,7 @@ GEM
238300
listen (3.9.0)
239301
rb-fsevent (~> 0.10, >= 0.10.3)
240302
rb-inotify (~> 0.9, >= 0.9.10)
303+
localhost (1.3.1)
241304
loofah (2.22.0)
242305
crass (~> 1.0.2)
243306
nokogiri (>= 1.12.0)
@@ -246,6 +309,7 @@ GEM
246309
net-imap
247310
net-pop
248311
net-smtp
312+
mapping (1.1.1)
249313
marcel (1.0.4)
250314
matrix (0.4.2)
251315
method_source (1.1.0)
@@ -281,6 +345,7 @@ GEM
281345
faraday (>= 1, < 3)
282346
sawyer (~> 0.9)
283347
open4 (1.3.4)
348+
openssl (3.2.0)
284349
orm_adapter (0.5.0)
285350
paper_trail (15.1.0)
286351
activerecord (>= 6.1)
@@ -290,6 +355,22 @@ GEM
290355
ast (~> 2.4.1)
291356
racc
292357
pg (1.5.6)
358+
process-metrics (0.2.1)
359+
console (~> 1.8)
360+
samovar (~> 2.1)
361+
protocol-hpack (1.4.3)
362+
protocol-http (0.26.5)
363+
protocol-http1 (0.19.1)
364+
protocol-http (~> 0.22)
365+
protocol-http2 (0.17.0)
366+
protocol-hpack (~> 1.4)
367+
protocol-http (~> 0.18)
368+
protocol-rack (0.5.1)
369+
protocol-http (~> 0.23)
370+
rack (>= 1.0)
371+
protocol-redis (0.8.1)
372+
protocol-websocket (0.13.0)
373+
protocol-http (~> 0.2)
293374
pry (0.14.2)
294375
coderay (~> 1.1)
295376
method_source (~> 1.0)
@@ -299,8 +380,6 @@ GEM
299380
psych (5.1.2)
300381
stringio
301382
public_suffix (5.0.5)
302-
puma (6.4.2)
303-
nio4r (~> 2.0)
304383
raabro (1.4.0)
305384
racc (1.8.0)
306385
rack (3.0.11)
@@ -421,6 +500,9 @@ GEM
421500
rubyzip (2.3.2)
422501
rufus-scheduler (3.9.1)
423502
fugit (~> 1.1, >= 1.1.6)
503+
samovar (2.3.0)
504+
console (~> 1.0)
505+
mapping (~> 1.0)
424506
sass-rails (6.0.0)
425507
sassc-rails (~> 2.1, >= 2.1.1)
426508
sassc (2.4.0)
@@ -466,8 +548,11 @@ GEM
466548
terminal-table (3.0.2)
467549
unicode-display_width (>= 1.1.1, < 3)
468550
thor (1.3.1)
551+
thread-local (1.1.0)
469552
tilt (2.3.0)
470553
timeout (0.4.1)
554+
timers (4.3.5)
555+
traces (0.11.1)
471556
trailblazer-option (0.1.2)
472557
tzinfo (2.0.6)
473558
concurrent-ruby (~> 1.0)
@@ -502,16 +587,20 @@ PLATFORMS
502587

503588
DEPENDENCIES
504589
ar-uuid
590+
async-io
591+
async-redis
592+
async-websocket
505593
bcrypt (~> 3.1.19)
506594
bootsnap (>= 1.1.0)
507595
brakeman
508596
bundler-audit
509-
capybara
510597
danger
511598
database_cleaner
512599
devise
513600
factory_bot_rails
514601
faker
602+
falcon
603+
falcon-capybara
515604
faraday-retry
516605
ffaker
517606
grape
@@ -524,7 +613,6 @@ DEPENDENCIES
524613
paper_trail
525614
pg (>= 0.18, < 2.0)
526615
pry-byebug
527-
puma (~> 6.3)
528616
rails (~> 7)
529617
redis (~> 5.0)
530618
rspec-rails
@@ -542,6 +630,7 @@ DEPENDENCIES
542630
sidekiq-scheduler
543631
spring
544632
spring-watcher-listen (~> 2.1.0)
633+
thread-local
545634
tzinfo-data
546635
uglifier (>= 1.3.0)
547636
ulid-rails!

app/assets/javascripts/client.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
function connectToChatServer(url) {
2+
console.log("WebSocket Connecting...", url);
3+
var server = new WebSocket(url.href);
4+
5+
server.onopen = function(event) {
6+
console.log("WebSocket Connected:", server);
7+
chat.disabled = false;
8+
9+
chat.onkeypress = function(event) {
10+
if (event.keyCode == 13) {
11+
server.send(JSON.stringify({text: chat.value}));
12+
13+
chat.value = "";
14+
}
15+
}
16+
};
17+
18+
server.onmessage = function(event) {
19+
console.log("WebSocket Message:", event);
20+
21+
var message = JSON.parse(event.data);
22+
23+
var pre = document.createElement('pre');
24+
pre.innerText = message.text;
25+
26+
response.appendChild(pre);
27+
};
28+
29+
server.onerror = function(event) {
30+
console.log("WebSocket Error:", event);
31+
chat.disabled = true;
32+
server.close();
33+
};
34+
35+
server.onclose = function(event) {
36+
console.log("WebSocket Close:", event);
37+
38+
setTimeout(function() {
39+
connectToChatServer(url);
40+
}, 1000);
41+
};
42+
}
43+
44+
var url = new URL('/connect', window.location.href);
45+
url.protocol = url.protocol.replace('http', 'ws');
46+
47+
connectToChatServer(url);

app/assets/stylesheets/application.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@
1313
*= require_tree .
1414
*= require_self
1515
*/
16+
17+
body {
18+
background: #000;
19+
color: #fff;
20+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# frozen_string_literal: true
22

3+
# Every controller should inherit this
34
class ApplicationController < ActionController::Base
5+
def logger
6+
Rails.logger
7+
end
48
end

0 commit comments

Comments
 (0)