[英]keeping an activity just for production Elixir Phoenix
I am doing as written below in my project. 我在下面的项目中写的如下。 But I only want to run it in Production mode, not in development mode, for this, I tried with Mix.env
and it worked locally by giving me :dev
or :prod
but It didn't work on online API. 但我只想在生产模式下运行它,而不是在开发模式下,为此,我尝试使用Mix.env
,它在本地工作,给我:dev
或:prod
但它不适用于在线API。 It got an error as there is nothing like env. 它有一个错误,因为没有像env那样的东西。
I want to make it just for production with some kind of pattern matching function 我想通过某种模式匹配功能来制作它
Task.start(fn ->
if user |> Intercom.get_user |> intercom_user? do
Logger.info "User '#{user.username}' already present at Intercom."
else
Intercom.create_user(user, user_agent, requester_ip)
end
end)
any help will be appreciated! 任何帮助将不胜感激!
You'll have to set a config for this in the config/*.exs
files as Mix
is usually not included in production releases. 您必须在config/*.exs
文件中为此设置配置,因为Mix
通常不包含在生产版本中。 You could just store the env value or a more meaningful name like :create_intercom_user
. 您可以只存储env值或更有意义的名称,如:create_intercom_user
。
In config/dev.exs
and config/test.exs
: 在config/dev.exs
和config/test.exs
:
config :my_app, :create_intercom_user, false
In config/prod.exs
: 在config/prod.exs
:
config :my_app, :create_intercom_user, true
and then in your code: 然后在你的代码中:
if Application.get_env(:my_app, :create_intercom_user) do
Task.start(fn -> ... end)
end
or: 要么:
In config/config.exs
: 在config/config.exs
:
config :my_app, :mix_env, Mix.env
and in your code: 在你的代码中:
if Application.get_env(:my_app, :mix_env) == :prod do
Task.start(fn -> ... end)
end
(Replace :my_app
with your app's name.) (替换:my_app
与您的应用名称。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.