WeChat.RefreshTimer (wechat v0.2.0)

token 刷新器

这个是默认的刷新器,当然也支持自定义的刷新器,可以这样配置:


config :wechat, :refresh_timer, YourRefreshTimer

# or with state

config :wechat, :refresh_timer, {YourRefreshTimer, state}

默认的刷新器支持多种配置:

配置1

config :wechat, :refresh_settings, [ClientA, ClientB, ClientC]

以上配置会自动为三个 Client 定时刷新 token ,默认会在 token 过期前 30 分钟刷新,token 刷新失败的重试间隔为 1 分钟, 默认的 token 刷新列表为:WeChat.RefreshHelper.get_refresh_options_by_client/1 输出的结果

配置2

config :wechat, :refresh_settings, [{ClientA, options}, ClientB, ClientC]

# or

config :wechat, :refresh_settings, %{ClientA => options, ClientB => options, ClientC => options}

options 配置说明见:options/0

为了适应 StorageRefreshTimer 启动之后才启动,可以开启延时启动刷新:

config :wechat, WeChat.RefreshTimer, wait_for_signal: true

当所有的 Storage 都已经完成,可以即可通过 WeChat.RefreshTimer.start_monitor/0 方法刷新 token

不配置默认为立即启动刷新

Link to this section Summary

Types

option

token 过去前多少秒刷新,单位:秒

刷新 token 失败的重试间隔,单位:秒

Link to this section Types

Specs

options() :: %{
  optional(:refresh_before_expired) => refresh_before_expired(),
  optional(:refresh_retry_interval) => refresh_retry_interval(),
  optional(:refresh_options) => WeChat.RefreshHelper.refresh_options()
}

option

  • :refresh_before_expired: 在 token 过去前多少秒刷新,单位:秒,可选, server_role=hub 时, 默认值:2 * 1800 秒; 其余角色默认值:1800
  • :refresh_retry_interval: 刷新 token 失败的重试间隔,单位:秒,可选,默认值:60000
  • :refresh_options: 刷新 token 配置,可选,默认值:WeChat.RefreshHelper.get_refresh_options_by_client/1 的输出结果
Link to this type

refresh_before_expired()

Specs

refresh_before_expired() :: non_neg_integer()

token 过去前多少秒刷新,单位:秒

如果server_role = hub, hub server 的值请大于 hub client

Link to this type

refresh_retry_interval()

Specs

refresh_retry_interval() :: non_neg_integer()

刷新 token 失败的重试间隔,单位:秒

Link to this section Functions

Link to this function

add(client, opts)

Specs

add(WeChat.client(), options()) :: :ok
Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

refresh(client)

Specs

refresh(WeChat.client()) :: :ok | :nofound
Link to this function

refresh_key(store_id, store_key, value, expired_time, client)

Specs

Specs

remove(WeChat.client()) :: :ok
Link to this function

start_link(state \\ %{})

Specs

start_link(state :: %{required(WeChat.client()) => options()}) ::
  GenServer.on_start()
Link to this function

start_monitor()

Specs

start_monitor() :: :ok