Commit 3dbfc420 authored by Mikko Ahlroth's avatar Mikko Ahlroth

Allow pulses from the future to deal with clock drift

Also fixed repo links to point to Github.
parent a2a5f122
......@@ -41,7 +41,7 @@ defmodule CodeStats.PulseController do
{user, machine} = AuthUtils.get_api_details(conn)
with {:ok, %DateTime{} = datetime} <- parse_timestamp(timestamp),
:ok <- check_datetime_diff(datetime),
{:ok, datetime} <- check_datetime_diff(datetime),
{:ok, %Pulse{} = pulse} <- create_pulse(user, machine, datetime),
:ok <- create_xps(pulse, xps) do
:ok
......@@ -60,15 +60,19 @@ defmodule CodeStats.PulseController do
{:ok, diff, _, type} = DateTime.diff(DateTime.now_utc(), datetime)
if type == :after and diff <= @datetime_max_diff do
:ok
{:ok, datetime}
else
{:error, :generic, "Invalid date."}
if type == :before or type == :same_time do
{:ok, DateTime.now_utc()}
else
{:error, :generic, "Invalid date."}
end
end
end
defp create_pulse(user, machine, datetime) do
params = %{"sent_at" => datetime}
Pulse.changeset(%Pulse{}, params)
|> Changeset.put_change(:user_id, user.id)
|> Changeset.put_change(:machine_id, machine.id)
......
<h2>Changelog</h2>
<h3>1.1.1 – Clock drift</h3>
<ul>
<li>Fixed a case where clock drift either on the client or the server caused pulses to not be accepted.</li>
</ul>
<h3>1.1.0 – First public release</h3>
<p>
......
......@@ -10,12 +10,12 @@
<ul>
<li>
<strong>Code::Stats main site:</strong>
<a href="https://bitbucket.org/vincit/codestats/">https://bitbucket.org/vincit/codestats/</a>
<a href="https://github.com/Nicd/code-stats">https://github.com/Nicd/code-stats</a>
</li>
<li>
<strong>Atom plugin:</strong>
<a href="https://bitbucket.org/vincit/codestats-atom/">https://bitbucket.org/vincit/codestats-atom/</a>
<a href="https://github.com/Nicd/code-stats-atom">https://github.com/Nicd/code-stats-atom</a>
</li>
</ul>
</p>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment