@@ -99,7 +99,7 @@ defmodule Core.Services.Clusters do
9999 Saves a usage record for a given cluster
100100 """
101101 @ spec save_usage ( map , Cluster . t ) :: { :ok , ClusterUsageHistory . t } | error
102- def save_usage ( attrs , % Cluster { id: id , account_id: account_id } ) do
102+ def save_usage ( % { } = attrs , % Cluster { id: id , account_id: account_id } ) do
103103 start_transaction ( )
104104 |> add_operation ( :usage , fn _ ->
105105 % ClusterUsageHistory { cluster_id: id , account_id: account_id }
@@ -115,6 +115,7 @@ defmodule Core.Services.Clusters do
115115 end )
116116 |> execute ( extract: :usage )
117117 end
118+ def save_usage ( nil , % Cluster { id: id , account_id: account_id } ) , do: { :ok , nil }
118119
119120 @ doc """
120121 Transfers ownership of a cluster to a new user. This has three main components:
@@ -161,15 +162,15 @@ defmodule Core.Services.Clusters do
161162 Pings a cluster and saves usage. Also meters the ingest if applicable
162163 """
163164 @ spec ping_cluster ( % { cluster: map , usage: map } , User . t ) :: cluster_resp
164- def ping_cluster ( % { cluster: % { provider: p , name: n } = cluster , usage: usage } , % User { } = user ) do
165+ def ping_cluster ( % { cluster: % { provider: p , name: n } = cluster } = attrs , % User { } = user ) do
165166 start_transaction ( )
166167 |> add_operation ( :cluster , fn _ ->
167168 Map . put ( cluster , :pinged_at , DateTime . utc_now ( ) )
168169 |> upsert_cluster ( p , n , user )
169170 end )
170- |> add_operation ( :usage , fn % { cluster: cluster } -> save_usage ( usage , cluster ) end )
171+ |> add_operation ( :usage , fn % { cluster: cluster } -> save_usage ( attrs [ : usage] , cluster ) end )
171172 |> add_operation ( :meter , fn _ ->
172- case usage do
173+ case attrs [ : usage] do
173174 % { bytes_ingested: bytes } when is_integer ( bytes ) and bytes > 0 ->
174175 Logger . info ( "Deferring ingest metering for #{ bytes } bytes for user #{ user . email } " )
175176 Core.Services.Payments . defer_ingest ( user , bytes )
0 commit comments