Skip to content

Commit

Permalink
Merge pull request #26 from otobus/mustafaturan/update_time_spent_cal…
Browse files Browse the repository at this point in the history
…culation

Update time spent calculation for EventSource block
  • Loading branch information
Mustafa TURAN authored May 27, 2018
2 parents eb28cd8 + 7c2c6f7 commit d54369d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [1.3.X]


- Update time spent calculation for EventSource block
- Remove support for system event tracing (Updated the wiki to create wrapper for system event tracing)

## [1.2.X] - 2018.02.24
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ end

## Traceability

EventBus comes with a good enough data structure to track the event life cycle with its optional parameters. For a traceable system, it is highly recommend to fill optional fields on event data. It is also encouraged to use `Event.nofify` block/yield to automatically set the `initialized_at` and `occurred_at` values.
EventBus comes with a good enough data structure to track the event life cycle with its optional parameters. For a traceable system, it is highly recommend to fill optional fields on event data. It is also encouraged to use `EventSource.nofify` block/yield to automatically set the `initialized_at` and `occurred_at` values.

### System Events

Expand Down
6 changes: 5 additions & 1 deletion lib/event_bus/event_source.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule EventBus.EventSource do
defmacro __using__(_) do
quote do
require EventBus.EventSource

alias EventBus.EventSource
alias EventBus.Model.Event
end
Expand All @@ -20,6 +21,7 @@ defmodule EventBus.EventSource do
"""
defmacro build(params, do: yield) do
quote do
started_at = System.monotonic_time(:micro_seconds)
initialized_at = System.os_time(:micro_seconds)
params = unquote(params)

Expand All @@ -35,13 +37,15 @@ defmodule EventBus.EventSource do
{params[:topic], result}
end

time_spent = System.monotonic_time(:micro_seconds) - started_at

%Event{
id: params[:id],
topic: topic,
transaction_id: params[:transaction_id],
data: data,
initialized_at: initialized_at,
occurred_at: System.os_time(:micro_seconds),
occurred_at: initialized_at + time_spent,
source: source,
ttl: params[:ttl]
}
Expand Down

0 comments on commit d54369d

Please sign in to comment.