Skip to content

Commit 23603aa

Browse files
Modernize code + expanded test coverage.
1 parent 983db18 commit 23603aa

30 files changed

+897
-326
lines changed

.github/copilot-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Use Agent Context
44

5-
When working on this project, consult the `agent.md` file for project-specific guidelines, architecture decisions, and development patterns. This file contains curated information that will help you make better decisions aligned with the project's goals and standards.
5+
When working on this project, consult the `agents.md` file for project-specific guidelines, architecture decisions, and development patterns. This file contains curated information that will help you make better decisions aligned with the project's goals and standards.
66

77
If the file does not exist, you will need to install it, by running the following command:
88

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/agent.md
1+
/agents.md
22
/.context
33
/.bundle
44
/pkg

.rubocop.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
plugins:
2+
- rubocop-md
23
- rubocop-socketry
34

45
AllCops:
56
DisabledByDefault: true
67

8+
# Socketry specific rules:
9+
710
Layout/ConsistentBlankLineIndentation:
811
Enabled: true
912

13+
Layout/BlockDelimiterSpacing:
14+
Enabled: true
15+
16+
Style/GlobalExceptionVariables:
17+
Enabled: true
18+
19+
# General Layout rules:
20+
1021
Layout/IndentationStyle:
1122
Enabled: true
1223
EnforcedStyle: tabs
@@ -33,6 +44,9 @@ Layout/BeginEndAlignment:
3344
Enabled: true
3445
EnforcedStyleAlignWith: start_of_line
3546

47+
Layout/RescueEnsureAlignment:
48+
Enabled: true
49+
3650
Layout/ElseAlignment:
3751
Enabled: true
3852

@@ -41,10 +55,15 @@ Layout/DefEndAlignment:
4155

4256
Layout/CaseIndentation:
4357
Enabled: true
58+
EnforcedStyle: end
4459

4560
Layout/CommentIndentation:
4661
Enabled: true
4762

63+
Layout/FirstHashElementIndentation:
64+
Enabled: true
65+
EnforcedStyle: consistent
66+
4867
Layout/EmptyLinesAroundClassBody:
4968
Enabled: true
5069

context/best-practices.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Create a single top-level `service.rb` file as your main entry point:
1414
#!/usr/bin/env async-service
1515

1616
# Load your service configurations
17-
require_relative 'lib/my_library/environment/web_environment'
18-
require_relative 'lib/my_library/environment/worker_environment'
17+
require_relative "lib/my_library/environment/web_environment"
18+
require_relative "lib/my_library/environment/worker_environment"
1919

2020
service "web" do
2121
include MyLibrary::Environment::WebEnvironment
@@ -159,9 +159,9 @@ module WebEnvironment
159159
def port
160160
3000
161161
end
162-
162+
163163
def host
164-
'0.0.0.0'
164+
"0.0.0.0"
165165
end
166166
end
167167

@@ -172,7 +172,7 @@ module WorkerEnvironment
172172
end
173173

174174
def queue_name
175-
'default'
175+
"default"
176176
end
177177

178178
def count
@@ -254,7 +254,7 @@ class WebService < Async::Service::ContainerService
254254

255255
super
256256
end
257-
257+
258258
def stop
259259
@endpoint&.close
260260
end
@@ -302,7 +302,7 @@ describe MyLibrary::Service::WebService do
302302
before do
303303
controller.start
304304
end
305-
305+
306306
after do
307307
controller.stop
308308
end

context/getting-started.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Create a simple service that runs continuously:
2929
```ruby
3030
#!/usr/bin/env async-service
3131

32-
require 'async/service'
32+
require "async/service"
3333

3434
class HelloService < Async::Service::Generic
3535
def setup(container)
@@ -99,7 +99,7 @@ You can define multiple services in a single configuration file:
9999
```ruby
100100
#!/usr/bin/env async-service
101101

102-
require 'async/service'
102+
require "async/service"
103103

104104
class WebService < Async::Service::Generic
105105
def setup(container)
@@ -141,7 +141,7 @@ end
141141
You can also create and run services programmatically:
142142

143143
```ruby
144-
require 'async/service'
144+
require "async/service"
145145

146146
configuration = Async::Service::Configuration.build do
147147
service "my-service" do

context/service-architecture.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,11 @@ module ContainerEnvironment
439439
def count
440440
4
441441
end
442-
442+
443443
def restart
444444
true
445445
end
446-
446+
447447
def health_check_timeout
448448
30
449449
end

examples/ipc/client.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,30 @@ def setup(container)
2323
container.run(count: 1, restart: true) do |instance|
2424
socket_path = evaluator.ipc_socket_path
2525

26-
Console.info(self) {"IPC Client starting - will connect to #{socket_path}"}
26+
Console.info(self){"IPC Client starting - will connect to #{socket_path}"}
2727
instance.ready!
2828

2929
while true
3030
begin
3131
# Connect to server
3232
client = UNIXSocket.new(socket_path)
33-
Console.info(self) {"Connected to server"}
33+
Console.info(self){"Connected to server"}
3434

3535
# Read response
3636
response = client.readline.chomp
3737
puts "📨 Received: #{response}"
3838

3939
client.close
40-
Console.info(self) {"Connection closed"}
40+
Console.info(self){"Connection closed"}
4141

4242
# Wait before next connection
4343
sleep(2)
4444

4545
rescue Errno::ENOENT
46-
Console.warn(self) {"Server socket not found at #{socket_path}, retrying..."}
46+
Console.warn(self){"Server socket not found at #{socket_path}, retrying..."}
4747
sleep(3)
4848
rescue Errno::ECONNREFUSED
49-
Console.warn(self) {"Connection refused, server may not be ready"}
49+
Console.warn(self){"Connection refused, server may not be ready"}
5050
sleep(3)
5151
rescue => error
5252
Console.error(self, error)

examples/ipc/server.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ def setup(container)
2828
# Create Unix domain socket server
2929
server = UNIXServer.new(socket_path)
3030

31-
Console.info(self) {"IPC Server listening on #{socket_path}"}
31+
Console.info(self){"IPC Server listening on #{socket_path}"}
3232
instance.ready!
3333

3434
begin
3535
while true
3636
# Accept incoming connections
3737
client = server.accept
38-
Console.info(self) {"Client connected from PID #{client.peereid[0]}"}
38+
Console.info(self){"Client connected from PID #{client.peereid[0]}"}
3939

4040
# Send greeting with timestamp
4141
timestamp = Time.now.strftime("%H:%M:%S")
4242
client.write("Hello World at #{timestamp}\n")
4343
client.close
4444

45-
Console.info(self) {"Sent greeting and closed connection"}
45+
Console.info(self){"Sent greeting and closed connection"}
4646
end
4747
rescue => error
4848
Console.error(self, error)

examples/ipc/service.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
require "socket"
88
require "async"
9-
require "async/service/container_service"
10-
require "async/service/container_environment"
9+
require "async/service/managed/service"
10+
require "async/service/managed/environment"
1111

1212
# Server service that listens on a Unix domain socket and responds with "Hello World"
13-
class IPCServer < Async::Service::ContainerService
13+
class IPCServer < Async::Service::Managed::Service
1414
def run(instance, evaluator)
1515
socket_path = evaluator.ipc_socket_path
1616

@@ -20,20 +20,20 @@ def run(instance, evaluator)
2020
# Create Unix domain socket server
2121
server = UNIXServer.new(socket_path)
2222

23-
Console.info(self) {"IPC Server listening on #{socket_path}"}
23+
Console.info(self){"IPC Server listening on #{socket_path}"}
2424
instance.ready!
2525

2626
begin
2727
while true
2828
# Accept incoming connections
2929
client = server.accept
30-
Console.info(self) {"Client connected"}
30+
Console.info(self){"Client connected"}
3131

3232
# Send greeting
3333
client.write("Hello World\n")
3434
client.close
3535

36-
Console.info(self) {"Sent greeting and closed connection"}
36+
Console.info(self){"Sent greeting and closed connection"}
3737
end
3838
rescue => error
3939
Console.error(self, error)
@@ -47,12 +47,12 @@ def run(instance, evaluator)
4747
end
4848

4949
# Client service that periodically connects to the server
50-
class IPCClient < Async::Service::ContainerService
50+
class IPCClient < Async::Service::Managed::Service
5151
def run(instance, evaluator)
5252
socket_path = evaluator.ipc_socket_path
5353
timeout = evaluator.ipc_connection_timeout
5454

55-
Console.info(self) {"IPC Client starting - will connect to #{socket_path}"}
55+
Console.info(self){"IPC Client starting - will connect to #{socket_path}"}
5656
instance.ready!
5757

5858
Async do |task|
@@ -63,20 +63,20 @@ def run(instance, evaluator)
6363

6464
# Connect to server
6565
client = UNIXSocket.new(socket_path)
66-
Console.info(self) {"Connected to server"}
66+
Console.info(self){"Connected to server"}
6767

6868
# Read response
6969
response = client.readline.chomp
7070
puts "Received from server: #{response}"
7171

7272
client.close
73-
Console.info(self) {"Connection closed"}
73+
Console.info(self){"Connection closed"}
7474

7575
# Wait before next connection
7676
task.sleep(3)
7777

7878
rescue Errno::ENOENT
79-
Console.warn(self) {"Server socket not found at #{socket_path}, retrying..."}
79+
Console.warn(self){"Server socket not found at #{socket_path}, retrying..."}
8080
task.sleep(2)
8181
rescue => error
8282
Console.error(self, error)
@@ -88,7 +88,7 @@ def run(instance, evaluator)
8888
end
8989

9090
module IPCEnvironment
91-
include Async::Service::ContainerEnvironment
91+
include Async::Service::Managed::Environment
9292

9393
def ipc_socket_path
9494
File.expand_path("service.ipc", Dir.pwd)

gems.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
gem "decode"
2424

2525
gem "rubocop"
26+
gem "rubocop-md"
2627
gem "rubocop-socketry"
2728

29+
gem "sus-fixtures-async"
30+
2831
gem "bake"
2932
gem "bake-test"
3033
gem "bake-test-external"

0 commit comments

Comments
 (0)