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
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
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.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
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.Management.UserProject do | |
@moduledoc """ | |
UserProject module | |
""" | |
use Ecto.Schema | |
import Ecto.Changeset | |
alias MyApp.Accounts.User | |
alias MyApp.Management.Project |
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 MyApp.Management.Project do | |
... | |
many_to_many( | |
:users, | |
User, | |
join_through: "user_project", | |
on_replace: :delete | |
) | |
... |
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, project_ids) when is_list(project_ids) do | |
projects = | |
Project | |
|> where([project], project.id in ^project_ids) | |
|> Repo.all() | |
with {:ok, _struct} <- | |
user | |
|> User.changeset_update_projects(projects) | |
|> Repo.update() do |
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.Management.UserProject do | |
@moduledoc """ | |
UserProject module | |
""" | |
use Ecto.Schema | |
import Ecto.Changeset | |
alias MyApp.Accounts.User | |
alias MyApp.Management.Project |
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
upstream phoenix { | |
server 127.0.0.1:4000 max_fails=5 fail_timeout=60s; | |
} | |
server { | |
root /var/www/html; | |
# Add index.php to the list if you are using PHP | |
index index.html index.htm index.nginx-debian.html; | |
server_name <server_name>; | |
location / { | |
# First attempt to serve request as file, then |