Skip to content

Commit

Permalink
Add versioned interrupt signal to support older versions of Crystal
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgi Kavrelishvili authored and Giorgi Kavrelishvili committed May 11, 2024
1 parent 305356f commit cffdefe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/grip.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ require "./grip/routers/*"
require "./grip/*"

module Grip; end

class Application < Grip::Application
def initialize()
super("development", false)
end
end

app = Application.new
app.run
24 changes: 23 additions & 1 deletion src/grip/application.cr
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,29 @@ module Grip
Log.info { "Listening at #{schema}://#{host}:#{port}" }

if @environment != "test"
Process.on_interrupt { exit }
{% begin %}
{% version = Crystal::VERSION.split(".").map(&.to_i) %}

{% major = version[0] %}
{% minor = version[1] %}
{% patch = version[2] %}

# 0.X.X
{% if major < 1 %}
Signal::INT.trap { exit }
{% end %}

# 1.0.0 to 1.11.X
{% if major == 1 && minor < 12 %}
Process.on_interrupt { exit }
{% end %}

# 1.12.X to 1.X.X
{% if major == 1 && minor >= 12 %}
Process.on_terminate { exit }
{% end %}
{% end %}

server.listen
end
end
Expand Down

0 comments on commit cffdefe

Please sign in to comment.