Packages

A library for generating fake GPS data or load GPS from GPX file/string using for dev/test. The library generates GPSs for simulating a route and scalable for test workload.

Current section

Files

Jump to
location_simulator lib callback_event.ex
Raw

lib/callback_event.ex

defmodule LocationSimulator.Event do
@moduledoc """
Callback api is a brigde for worker call your code.
Has three callback apis: start/2, event/2, stop/2
All these have 2 parameters is config & state.
config includes lib's config and your meta data you need pass to module.
state is data that is generated by worker. state is an Elixir map with key:
:start_time - Timestamp the worker start.
:success - Number of event success.
:failed - Number of event failed.
:error - Number of event error
:gps - GPS data of current state.
:stop_time - Timestamp worker done, only in stop callback api.
GPS data is map with key:
:timestamp - delta time in milisecond from last event.
:long - Longitude
:lati - Latitude
:alti - Altitude
## Example
Please go to example folder in [repo](https://github.com/ohhi-vn/location_simulator)
"""
@doc """
start event will be trigger when worker start.
In this event gps & :end_time won't exist.
result return to worker for success is {:ok, new_config}. new_config will be used for next event.
if return {:error, reason} the worker will stop working.
"""
@callback start(config :: map, state :: map) :: {:ok, map} | {:error, reason :: any}
@doc """
event callback will be trigger every worker generated a new GPS data.
If result is {:stop, reason} the worker will stop working.
"""
@callback event(config :: map, state :: map) :: {:ok, map} | {:error, reason :: any} | {:stop, reason :: any}
@doc """
stop will be trigger when worker send enough gps event.
"""
@callback stop(config :: map, state :: map) :: {:ok, map} | {:error, reason :: any}
end