Permalink
Browse files

Merge branch 'correct-call'

Conflicts:
	src/safetyvalve.app.src
  • Loading branch information...
jlouis committed Dec 23, 2012
2 parents 9287185 + 85a1691 commit f2d723a6c130b3638d2ffc053320344e4ff696e3
Showing with 28 additions and 5 deletions.
  1. +15 −0 README.md
  2. +1 −1 eqc_test/worker.erl
  3. +1 −1 src/safetyvalve.app.src
  4. +9 −1 src/sv.erl
  5. +2 −2 test/sv_SUITE.erl
View
@@ -5,6 +5,21 @@ Erlang systems. It provides queueing facilities for tasks to be
executed so their concurrency and rate can be limited on a running
system.
+# Using
+
+This project uses semantic versioning. Tags are declared like `vX.Y.Z`
+(do note the `v`). The meaning is:
+
+* X changes: There have been backwards-incompatible changes to the `sv` API functions which are meant to be the only functions exported. Or there has been changes to the way the configuration file format is specified.
+* Y changes: These are additions to the API, but existing functionality has not been broken.
+* Z changes: Bug fixes.
+
+# Changes
+
+### v0.1.0 -> v1.0.0
+
+The return value of `sv:run/3` changed from `Res | {error, Reason}` to `{ok, Res} | {error, Reason}`. This better reflects the system and we can distinguish between an error term from the function we run and safetyvalve itself.
+
# Inspiration
Safetyvalve owes its inspiration to Ulf Wigers `jobs` framework, but
View
@@ -14,7 +14,7 @@ do_work(TimePoint) ->
fun () ->
done = manager:doing_work()
end) of
- done -> manager:status(done);
+ {ok, done} -> manager:status(done);
{error, _Reason} = Err -> manager:status(Err)
end.
View
@@ -1,7 +1,7 @@
{application, safetyvalve,
[
{description, "A safety valve for your erlang node"},
- {vsn, "0.1.1"},
+ {vsn, "1.0.0"},
{registered, [safetyvalve_sup]},
{applications, [
kernel,
View
@@ -11,12 +11,19 @@
%% function will return either the result of `Fun' or an `{error,
%% Reason}' error term, describing the overload situation encountered.</p>
%% @end
+-spec run(Name, TS, Fun) -> {ok, Result} | {error, Reason}
+ when
+ Name :: atom(),
+ TS :: term(), % Timestamp, should be orderable and unique
+ Fun :: fun (() -> term),
+ Result :: term(),
+ Reason :: term().
run(Name, TimePoint, Fun) ->
case sv_queue:ask(Name, TimePoint) of
{go, Ref} ->
Res = Fun(),
sv_queue:done(Name, Ref),
- Res;
+ {ok, Res};
{error, Reason} ->
{error, Reason}
end.
@@ -27,6 +34,7 @@ run(Name, Fun) ->
run(Name, timestamp(), Fun).
%% @doc Construct a timestamp in a canonical way for Safetyvalve.
+-spec timestamp() -> term().
timestamp() ->
%% Timestamps *have* to be unique. Calling erlang:now/0 makes sure
%% this happens. But you can use any ordered term if you want, for instance
View
@@ -57,12 +57,12 @@ ping(_Config) ->
ok.
through(_Config) ->
- ok = sv:run(test_queue_1, fun work/0).
+ {ok, ok} = sv:run(test_queue_1, fun work/0).
many_through(_Config) ->
Parent = self(),
Pids = [spawn_link(fun() ->
- ok = sv:run(test_queue_1, fun work/0),
+ {ok, ok} = sv:run(test_queue_1, fun work/0),
Parent ! {done, self()}
end) || _ <- lists:seq(1, 20)],
ok = collect(Pids).

0 comments on commit f2d723a

Please sign in to comment.