Skip to content

denielchiang/line_reminder

Repository files navigation

LineReminder

Run Tests Fly Deploy

A calendar website that is able to send a Line message when the scheduled job is triggered.

Prereq

  • Erlang 26.2.2
  • Elixir 1.16,1
  • Phoenix 1.7.12
  • Phoenix LiveView 0.18.16
  • PostgreSQL 15.3/16.1
  • Generate your own Line access token

Getting Started

To start your Phoenix server:

  • Run mix setup to install and setup dependencies
  • Start Phoenix endpoint with mix phx.server or inside IEx with iex -S mix phx.server

Now you can visit localhost:4000 from your browser.

Ready to run in production? Please check our deployment guides.

Seeds

Generate default message content, in this case the daliy bible reading chapter and paragraph

Development

Seeding by mix

$ mix run ./priv/repo/seeds.exs

Server

Seeding on runtime

iex> LineReminder.Release.seeds(2024)

Mix Tasks

Dependencies

Dependencies that using

Dev & Test environment

All environments

Deployment

It's using fly.io for my own convenience to save my infrastructure time & personal study. Feel free to change whatever you like if you wanna create your own scheduling Line Notifier, it has nothing to do with the deploymnet section.

There're 2 ways to do the deployment.

Elixir CI/CD via GitHub Actions

Which is the part of .github/workflows, you can find further information either GitHub or Fly.io. This action will be triggered by

  • PR - Run Tests that includes Compile, Check Formatting, Run Dialyzer, Check Code Consistency(Credo), Check Security(Sobelow), Test Cases.
  • Merge to main - Run Tests then deploy to Fly.io

Manually deploy

Require to install flyctl

brew install flyctl

Deploy from building server on Fly.io

fly deploy --remote-only

Common use Fly commands

Check apps status

fly apps list

Connect to Postgres that on Fly.io

 fly postgres connect -a <DB_NAME>

List secrets, environment variables, on Fly.io. Such as LINE_TOKEN in this case.

fly secrets list

Remove secret - LINE_TOKEN for example

fly secrets unset LINE_TOKEY

Set secret - LINE_TOKEN

fly secrets set LINE_TOKEN=<YOUR_LINE_TOKEN>

SSH to server

fly ssh console

Project log monitoring

fly logs

Scheduling tasks

Scheduling job is using quantum 3.5.

Config

It will be triggered on every 6am, Timezone GMT+8. Feel free to change your config/runtime.exs whenever you like.

  config :line_reminder, LineReminder.Scheduler,
   timezone: "Asia/Taipei",
   overlap: false,
   run_strategy: Quantum.RunStrategy.Local,
   jobs: [
     {"0 6 * * *", {LineReminder.Messanger, :send, []}}
   ]