Kitto v0.9.1 Kitto.Job.DSL View Source

A DSL to define jobs populating the widgets with data.

Link to this section Summary

Link to this section Functions

Link to this macro job(name, options, contents \\ []) View Source (macro)

Main API to define jobs.

Jobs can either be defined with a block or a command. When using a block, the expression represents data retrieval and any transformations required to broadcast events to the widgets. With command, the stdout and exit code of the command will be broadcasted to the widgets using the jobs name as the data source.

Data broadcast using commands is in the form {exit_code: integer, stdout: String.t}

Examples

use Kitto.Job.DSL

job :jenkins, every: :minute do
  jobs = Jenkins.jobs |> Enum.map(fn (%{"job" => job}) -> %{job: job.status} end)

  broadcast! :jenkins, %{jobs: jobs}
end

job :twitter, do: Twitter.stream("#elixir", &(broadcast!(:twitter, &1))

job :echo, every: :minute, command: "echo hello"

job :kitto_last_commit,
    every: {5, :minutes},
    command: "curl https://api.github.com/repos/kittoframework/kitto/commits?page=1&per_page=1"

Options

  • :every - Sets the interval on which the job will be performed. When it’s not specified, the job will be called once (suitable for streaming resources).

  • :first_at - A timeout after which to perform the job for the first time

  • :command - A command to be run on the server which will automatically broadcast events using the jobs name.