Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle timeout config for apns:connect/1 #171

Merged
merged 4 commits into from
May 15, 2017
Merged

handle timeout config for apns:connect/1 #171

merged 4 commits into from
May 15, 2017

Conversation

dcy
Copy link
Contributor

@dcy dcy commented May 13, 2017

Hi! When i use apns:connect/1 to open my connections, I must add the timeout config to sys.config:

{apns, [
    {timeout, 10000}
]},

%% for apns:connect/1
{push_confs, [
    #{id => apns1, certfile => "priv/apns1_cert.pem", keyfile => "priv/apns1_key.pem", is_dev_env => false, headers => #{}, timeout => 10000},
    #{id => apns2, certfile => "priv/apns2_cert.pem", keyfile => "priv/apns2_key.pem", is_dev_env => false, headers => #{apns_topic => "net.gzligo.LGTranslator"}, timeout => 10000}
]}

So i think the timeout should save in Connection, not use application:get_env(apns, timeout)(except default_connection).

@@ -332,10 +339,9 @@ get_device_path(DeviceId) ->
add_authorization_header(Headers, Token) ->
Headers#{apns_auth_token => <<"bearer ", Token/binary>>}.

-spec push(pid(), apns:device_id(), apns:headers(), notification()) ->
-spec push(pid(), apns:device_id(), apns:headers(), notification(), integer()) ->
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 342 is too long: -spec push(pid(), apns:device_id(), apns:headers(), notification(), integer()) ->.

@@ -228,8 +235,8 @@ handle_info(reconnect, State) ->
{ok, _} = timer:send_after(Sleep, reconnect),
{noreply, State#{backoff => Backoff + 1}}
end;
handle_info(timeout, #{gun_connection := GunConn, client := Client} = State) ->
{ok, Timeout} = application:get_env(apns, timeout),
handle_info(timeout, #{connection := Connection, gun_connection := GunConn, client := Client} = State) ->
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 238 is too long: handle_info(timeout, #{connection := Connection, gun_connection := GunConn, client := Client} = State) ->.

@@ -332,10 +340,9 @@ get_device_path(DeviceId) ->
add_authorization_header(Headers, Token) ->
Headers#{apns_auth_token => <<"bearer ", Token/binary>>}.

-spec push(pid(), apns:device_id(), apns:headers(), notification()) ->
-spec push(pid(), apns:device_id(), apns:headers(), notification(), integer()) ->
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 343 is too long: -spec push(pid(), apns:device_id(), apns:headers(), notification(), integer()) ->.

@ferigis
Copy link
Member

ferigis commented May 13, 2017

hi @dcy , thanks for your contribution.
I can't see what are the benefits of your change. Could you explain why using application:get_env/2 is not good?

@dcy
Copy link
Contributor Author

dcy commented May 13, 2017

When i use apns:connect/1(config like above), i must add {apns, [{timeout, 10000}]} to sys.config.
Or application:get_env(apns, timeout, 10000) is better.
It is not problem about application:get_env(apns, timeout), It is about when i do not want to use any application apns's config(application:get_env(apns, xxx)), I should add at least one timeout config {apns, [{timeout, 10000}]} to sys.config.

@elbrujohalcon
Copy link
Member

@ferigis also, @dcy's alternative makes the timeout configurable per-connection, instead of being an application-wide parameter.
In this PR I would object the use of maps:get in contrast of the more debugger friendly pattern-matching construct. In other words, I would use…

#{timeout := Timeout} = Connection

…instead of…

Timeout = maps:get(timeout, Connection)

…but that's just bike-shedding.

@ferigis ferigis merged commit f8c7390 into inaka:master May 15, 2017
@ferigis
Copy link
Member

ferigis commented May 15, 2017

@dcy merged! thanks for the contribution! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants