analytics/lib/mix/tasks/create_free_subscription.ex

27 lines
592 B
Elixir

defmodule Mix.Tasks.CreateFreeSubscription do
use Mix.Task
use Plausible.Repo
require Logger
alias Plausible.Billing.Subscription
@doc """
This is scheduled to run every 6 hours.
"""
def run([user_id]) do
Application.ensure_all_started(:plausible)
execute(user_id)
end
def run(_), do: IO.puts("Usage - mix create_free_subscription <user_id>")
def execute(user_id) do
user = Repo.get(Plausible.Auth.User, user_id)
Subscription.free(%{user_id: user_id})
|> Repo.insert!
IO.puts("Created a free subscription for user: #{user.name}")
end
end