Task.async not working in azure environment

I am using Task.async to move a task in background. It is working fine in my local.
But when the code is deployed to azure environment it is not working.
Is there anything specifically I need to mention to make it work in environment.
Please suggest. My code below:-
‘’’
a = Task.async(fn ->
verify_customer(current_user, first_pension)
end)
Task.await(a)

‘’’

Any suggestions, please.

We need more information, just “not working” doesn’t tell us what might be wrong. Is there a crash? Are ther error logs? How did you build and deploy the code to Azure?

Note that the example you provided doesn’t make much sense, as it’s nearly the same as just running verify_customer(current_user, first_pension) in the original process. What are you aiming to accomplish with this task?

1 Like

Have you tried running it without Task.async/await in prod? It’s really hard to help without error logs, the issue could be caused by a number of things unrelated to Task.async such as missing .env variables.

1 Like

Yes, looks like you are correct, though in my local it works fine but I am getting some exceptions in logs due to fallback controller. Not sure if that could be the cause of the failure in azure environment.
I am getting such error in logs:-

[error] #PID<0.3298.0> running MyFutureNowWeb.Endpoint (connection #PID<0.3297.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: POST /api_v2/pension/create
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in MyFutureNowWeb.FallbackController.call/2
        (my_future_now 4.0.0) lib/my_future_now_web/controllers/fallback_controller.ex:8: MyFutureNowWeb.FallbackController.call(%Plug.Conn{adapter: {Plug.Cowboy.Conn, :...}, assigns: %{user_signed_in?: true}, before_send: [#Function<0.28762384/1 in Plug.CSRFProtection.call/2>, #Function<2.77894870/1 in Phoenix.Controller.fetch_flash/2>, #Function<0.32542428/1 in Plug.Session.before_send/2>, #Function<0.66442134/1 in Plug.Telemetry.call/2>, #Function<0.92375621/1 in Phoenix.LiveReloader.before_send_inject_reloader/2>], body_params: %{"employee_pension" => %{"creation_journey_type" => "employer", "current_employment" => "false", "end_year" => "2010", "pension_provider_id" => "", "proposed_employer_name" => "ABC Limited", "proposed_policy_number" => "", "start_year" => "2007"}}, cookies: %{}, halted: false, host: "localhost", method: "POST", owner: #PID<0.3298.0>, params: %{"employee_pension" => %{"creation_journey_type" => "employer", "current_employment" => "false", "end_year" => "2010", "pension_provider_id" => "", "proposed_employer_name" => "ABC Limited", "proposed_policy_number" => "", "start_year" => "2007"}}, path_info: ["api_v2", "pension", "create"], path_params: %{}, port: 4000, private: %{MyFutureNowWeb.Router => {[], %{Bamboo.SentEmailViewerPlug => ["sent_emails"]}}, :phoenix_action => :create, :phoenix_controller => MyFutureNowWeb.APIV2.PensionController, :phoenix_endpoint => MyFutureNowWeb.Endpoint, :phoenix_flash => %{}, :phoenix_format => "json", :phoenix_layout => {MyFutureNowWeb.LayoutView, :app}, :phoenix_router => MyFutureNowWeb.Router, :phoenix_view => MyFutureNowWeb.APIV2.PensionView, :plug_session => %{}, :plug_session_fetch => :done, :plug_session_info => :ignore}, query_params: %{}, query_string: "", remote_ip: {127, 0, 0, 1}, req_cookies: %{}, req_headers: [{"accept", "*/*"}, {"accept-encoding", "gzip, deflate, br"}, {"accept-language", "en-US,en;q=0.9"}, {"authorization", "Bearer SFMyNTY.g3QAAAACZAAEZGF0YW0AAAAkN2VhZjM1NmUtNTE0MS00ZTJiLTkwZDctMTRkNzgwYjViZTJlZAAGc2lnbmVkbgYADKLsbXQB.-yVqBqUSsRJtflbU-rit8j205c3Hb1fwnH8ysNhKlxs"}, {"cache-control", "no-cache"}, {"connection", "keep-alive"}, {"content-length", "321"}, {"content-type", "application/json"}, {"host", "localhost:4000"}, {"origin", "chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop"}, {"postman-token", "d4922bac-7f43-4b65-2d7e-fb0bcc137c92"}, {"sec-fetch-dest", "empty"}, {"sec-fetch-mode", "cors"}, {"sec-fetch-site", "none"}, {"user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"}], request_path: "/api_v2/pension/create", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}, {"x-request-id", "FjLSWGVBjfYwu7kAAOxx"}], scheme: :http, script_name: [], secret_key_base: :..., state: :unset, status: nil}, {:ok, %MyFutureNow.Task{__meta__: #Ecto.Schema.Metadata<:loaded, "tasks">, admin_assignee: #Ecto.Association.NotLoaded<association :admin_assignee is not loaded>, admin_assignee_id: nil, admin_author: #Ecto.Association.NotLoaded<association :admin_author is not loaded>, admin_author_id: nil, body: nil, completed: false, completed_at: nil, completion_pension_status: "verify_customer_details", customer_pension: #Ecto.Association.NotLoaded<association :customer_pension is not loaded>, customer_pension_id: 844, due_date: ~D[2020-09-09], id: 457, inserted_at: ~N[2020-09-08 13:35:00.876097], priority: 1, snooze_count: 0, subject: "LexisNexis IDU FAIL, issue email to customer, set pensions to On Hold", updated_at: ~N[2020-09-08 13:35:00.876097], user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: 521, uuid: "7bb33496-6690-4780-955a-3852d0d49938"}})

Please note You are not using the right code fence to mark code… I updated your last post to show the difference. It should be ```

That error message is showing that your fallback controller cant match whats getting returned, which isn’t really the real error. Could you post the full function with async-await in it?

Issue is resolved…The problem was with the fallback controller. Thanks all.

2 Likes