This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def upsert_user_projects(user_id, project_ids) when is_list(project_ids) do | |
{:ok, time} = Ecto.Type.cast(:naive_datetime, Timex.now()) | |
project_users = | |
project_ids | |
|> Enum.uniq() | |
|> Enum.map(fn project_id -> | |
%{ | |
user_id: user_id, | |
project_id: project_id, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.TaskWorker do | |
use GenServer, restart: :transient | |
alias MyApp.Notify | |
alias MyApp.Management | |
alias MyApp.WorkerStateStorage | |
# client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.StarterWorker do | |
@moduledoc """ | |
Start lost children | |
""" | |
use GenServer | |
def start_link() do | |
GenServer.start_link(__MODULE__, []) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.TaskSupervisor do | |
use DynamicSupervisor | |
alias MyApp.Management | |
alias MyApp.WorkerStateStorage | |
def start_link(arg) do | |
DynamicSupervisor.start_link(__MODULE__, arg, name: __MODULE__) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: "2010-09-09" | |
Description: "Static website hosting with S3 and CloudFront" | |
Parameters: | |
BucketName: | |
Type: String | |
Default: "a-proper-bucket-name" | |
Resources: | |
# Create the bucket to contain the website HTML |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"key": "graphiql", | |
"lastId": 4, | |
"tabIds": [ | |
"tab1", | |
"tab2", | |
"tab3", | |
"tab4" | |
], | |
"closedTabs": [], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object :accounts_subscriptions do | |
field :accounts_user_count, :integer do | |
config(fn | |
_args, %{context: %{current_user: %{id: user_id}}} -> | |
{:ok, topic: "user_count:#{user_id}"} | |
_args, _context -> | |
{:error, Responses.get(:user_unauthorized)} | |
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def connect(%{"token" => token}, socket) do | |
with {:ok, user_id} <- | |
Phoenix.Token.verify(PhoenixAbsintheAuthenticatedSubscriptionsWeb.Endpoint, "user sesion", token, | |
max_age: 86_400 | |
), | |
%Accounts.User{} = current_user <- Accounts.lookup_user(user_id) do | |
socket = | |
Absinthe.Phoenix.Socket.put_options(socket, | |
context: %{ | |
current_user: current_user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handle_info(:reschedule, state) do | |
Accounts.list_users() | |
|> Enum.map(fn %{id: id} -> | |
Absinthe.Subscription.publish(PhoenixAbsintheAuthenticatedSubscriptionsWeb.Endpoint, Enum.random(1..10), | |
accounts_user_count: "user_count:#{id}" | |
) | |
end) | |
schedule_user_worker() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def me(_, _, %{context: %{current_user: user}}), | |
do: | |
{:ok, | |
%{ | |
user: user, | |
token: Phoenix.Token.sign(PhoenixAbsintheAuthenticatedSubscriptionsWeb.Endpoint, "user sesion", user.id) | |
}} |