Skip to content

Commit d739b72

Browse files
committedMar 11, 2020
prepare for deploy
1 parent 6822843 commit d739b72

File tree

8 files changed

+38
-14
lines changed

8 files changed

+38
-14
lines changed
 

‎config/config.exs

+3-1
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,6 @@ config :mauricio,
203203
}
204204

205205
import_config "#{Mix.env}.exs"
206-
import_config "secret.exs"
206+
if Mix.env != :prod do
207+
import_config "secret.exs"
208+
end

‎config/prod.exs

+6
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
import Config
2+
3+
config :nadia,
4+
token: System.get_env("TG_TOKEN")
5+
6+
config :mauricio,
7+
update_provider: :acceptor

‎config/releases.exs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import Config
2+
13
config :mauricio,
24
server: true,
3-
url: [host: System.get_env("APP_NAME") <> ".gigalixirapp.com", port: 443]
5+
url: [host: System.get_env("APP_NAME") <> ".gigalixirapp.com", port: 443],
6+
cat_api_token: System.get_env("CAT_API_TOKEN"),
7+
dog_api_token: System.get_env("DOG_API_TOKEN")

‎elixir_buildpack.config

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
elixir_version=1.10.1
2+
erlang_version=22.2

‎lib/mauricio.ex

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ defmodule Mauricio do
55
update_provider =
66
case Application.get_env(:mauricio, :update_provider) do
77
:poller -> [{Mauricio.Poller, []}]
8-
:acceptor -> [{Mauricio.Acceptor, []}]
8+
:acceptor ->
9+
url = Application.get_env(:mauricio, :url)
10+
[{Mauricio.Acceptor, url}]
911
nil -> []
1012
end
1113

@@ -19,6 +21,7 @@ defmodule Mauricio do
1921
end
2022

2123
def start_phase(:setup_webhook, :normal, _args) do
24+
IO.puts("Start webhook")
2225
case {
2326
Application.get_env(:mauricio, :update_provider),
2427
Application.get_env(:mauricio, :url)

‎lib/mauricio/acceptor.ex

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
defmodule Mauricio.Acceptor do
2-
# require Logger
32
alias Mauricio.CatChat
43
@behaviour :elli_handler
54

@@ -41,11 +40,20 @@ defmodule Mauricio.Acceptor do
4140
)
4241
end
4342

43+
def child_spec(args) do
44+
%{
45+
id: __MODULE__,
46+
start: {Mauricio.Acceptor, :start_link, [args]}
47+
}
48+
end
49+
4450
def tg_token do
4551
@tg_token
4652
end
4753

48-
def set_webhook(host) do
49-
Nadia.set_webhook(url: "#{host}/#{@tg_token}")
54+
def set_webhook(url) do
55+
host = url[:host]
56+
port = url[:port]
57+
Nadia.set_webhook(url: "#{host}:#{port}/#{@tg_token}")
5058
end
5159
end

‎mix.exs

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Mauricio.MixProject do
55
[
66
app: :mauricio,
77
version: "0.1.0",
8-
elixir: "~> 1.9",
8+
elixir: "~> 1.10",
99
start_permanent: Mix.env() == :prod,
1010
deps: deps()
1111
]
@@ -15,7 +15,7 @@ defmodule Mauricio.MixProject do
1515
def application do
1616
[
1717
applications: [:nadia],
18-
extra_applications: [:logger],
18+
extra_applications: [:logger, :elli],
1919
mod: {Mauricio, []},
2020
start_phases: [setup_webhook: []],
2121
]
@@ -24,15 +24,13 @@ defmodule Mauricio.MixProject do
2424
# Run "mix help deps" to learn about dependencies.
2525
defp deps do
2626
[
27+
{:elli, "~> 3.2"},
2728
{:nadia, "~> 0.6.0"},
28-
{:elli, "~> 3.0"},
2929
{:jason, "~> 1.1"},
3030
{:bookish_spork, github: "tank-bohr/bookish_spork", only: :test},
3131
{:ex_parameterized, "~> 1.3.7", only: :test},
3232
{:dialyxir, "~> 1.0.0-rc.7", only: :dev, runtime: false},
33-
{:rename, "~> 0.1.0", only: :dev}
34-
# {:dep_from_hexpm, "~> 0.3.0"},
35-
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
33+
{:rename, "~> 0.1.0", only: :dev},
3634
]
3735
end
3836
end

‎test/acceptor_test.exs

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ defmodule MauricioTest.Acceptor do
55
alias Mauricio.CatChat.Chats
66

77
setup_all do
8-
assert {:ok, _server_pid} = Mauricio.Acceptor.start_link(port: 4001)
8+
children = [{Mauricio.Acceptor, [port: 4001]}]
9+
assert {:ok, _server_pid} = Supervisor.start_link(children, strategy: :one_for_one)
910
:ok
1011
end
1112

@@ -50,7 +51,7 @@ defmodule MauricioTest.Acceptor do
5051
end
5152

5253
test "set webhook" do
53-
Acceptor.set_webhook("localhost:4001")
54+
Acceptor.set_webhook([host: "localhost", port: 4001])
5455
{:ok, request} = :bookish_spork.capture_request()
5556
url =
5657
request

0 commit comments

Comments
 (0)
Please sign in to comment.