Permalink
Browse files

Sync: Refresh the orders every night

  • Loading branch information...
adri committed Dec 9, 2017
1 parent 51be667 commit 12f9f12a0e361b1b4d2f2f825bc011589b94d9c6
Showing with 13 additions and 2 deletions.
  1. +6 −0 config/config.exs
  2. +2 −1 lib/picape/application.ex
  3. +1 −1 lib/picape/order/sync.ex
  4. +4 −0 lib/picape/scheduler.ex
@@ -17,6 +17,12 @@ config :picape, PicapeWeb.Endpoint,
pubsub: [name: Picape.PubSub,
adapter: Phoenix.PubSub.PG2]
config :picape, Picape.Scheduler,
jobs: [
# Runs every midnight:
{"@daily", {Picape.Order, :sync_supermarket, ["1"]}}
]
# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
@@ -15,8 +15,9 @@ defmodule Picape.Application do
# Start the endpoint when the application starts
supervisor(PicapeWeb.Endpoint, []),
supervisor(Absinthe.Subscription, [PicapeWeb.Endpoint]),
# Start your own worker by calling: Picape.Worker.start_link(arg1, arg2, arg3)
# Start your own worker by calling: Picape.Worker.start_link(arg1, arg2, arg3)
# worker(Picape.Worker, [arg1, arg2, arg3]),
worker(Picape.Scheduler, []),
supervisor(ConCache, [[ttl: :timer.hours(5)], [name: :supermarket]]),
]
@@ -25,7 +25,7 @@ defmodule Picape.Order.Sync do
end
defp overwrite(a, b) do
Map.merge(a, b, fn _id, quantity1, quantity2 -> quantity2 end)
Map.merge(a, b, fn _id, _quantity1, quantity2 -> quantity2 end)
end
defp find_changes(new, existing) do
@@ -0,0 +1,4 @@
defmodule Picape.Scheduler do
@moduledoc false
use Quantum.Scheduler, otp_app: :picape
end

0 comments on commit 12f9f12

Please sign in to comment.