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
# my_app.ex | |
defmodule MyApp do | |
alias MyApp.Jobs.TestJob | |
def test_work(use_batch?) do | |
1..100 | |
|> Enum.map(fn i -> %{job_number: i} end) | |
|> then(fn args_list -> | |
if use_batch? do | |
TestJob.new_batch(args_list, batch_callback_args: %{batch: :my_batch}) |
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
Mix.install([:benchee]) | |
defmodule Profile do | |
def function_that_throws(input) do | |
throw(input) | |
catch | |
value -> value | |
end | |
def function_that_returns(input) 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
#!/bin/bash | |
set -e | |
# Navigate to app directory | |
cd /home/<YOUR_USERNAME>/my_app | |
# Find the current release and the second newest release | |
current_release=$(ls ../releases | sort -nr | head -n 1) | |
previous_release=$(ls ../releases | sort -nr | tail -n +2 | head -n 1) |
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
... | |
config :my_app, MyAppWeb.Endpoint, | |
url: [host: "<YOUR_DOMAIN.COM>", port: 443], | |
cache_static_manifest: "priv/static/cache_manifest.json", | |
server: true, | |
force_ssl: [hsts: true], | |
http: [port: 4000, transport_options: [socket_opts: [:inet6]]], | |
https: [ | |
port: 4040, |
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
import Config | |
# Set ports based on environment variables in the release | |
http_port = System.get_env("HTTP_PORT") | |
https_port = System.get_env("HTTPS_PORT") | |
if http_port && https_port do | |
config :my_app, MyAppWeb.Endpoint, | |
http: [port: String.to_integer(http_port)], | |
https: [port: String.to_integer(https_port)] |
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
[Unit] | |
Description=My App | |
After=network.target | |
StartLimitIntervalSec=0 | |
[Service] | |
Type=simple | |
Restart=always | |
RestartSec=1 | |
User=<YOUR_USERNAME> |
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
#!/bin/bash | |
set -e | |
# Update to latest version of code | |
cd /home/<YOUR_USERNAME>/my_app | |
git fetch | |
git reset --hard origin/main | |
mix deps.get --only prod | |
# Optional CI steps |
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 MyAppWeb.Endpoint do | |
# All the stuff we just added | |
@session_options ... | |
socket ... | |
def www_redirect(conn, _options) do | |
if String.starts_with?(conn.host, "www.#{host()}") do | |
conn | |
|> Phoenix.Controller.redirect(external: "https://#{host()}") |
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
import Config | |
config :my_app, MyApp.Repo, | |
username: "postgres", | |
password: "<the random password you generated>", | |
database: "my_app", | |
hostname: "localhost", | |
pool_size: 10 | |
config :my_app, MyAppWeb.Endpoint, |
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 MyAppWeb.Endpoint do | |
use Phoenix.Endpoint, otp_app: :my_app | |
use SiteEncrypt.Phoenix | |
@impl Phoenix.Endpoint | |
def init(_key, config) do | |
{:ok, SiteEncrypt.Phoenix.configure_https(config)} | |
end | |
@impl SiteEncrypt |
NewerOlder