<commit_before>%% -*- erlang-indent-level: 4;indent-tabs-mode: nil; fill-column: 92 -*-
%% ex: ts=4 sw=4 et
%%% @author <NAME> <<EMAIL>>
%%% @copyright Copyright 2012-2012 Opscode Inc.
%%% @doc
%%% REST resource for monitoring status of pushy. Extracted from work done by <NAME> and <NAME> for erchef
%%% @end
-module(pushy_status_resource).

-export([init/1,
         allowed_methods/2,
         content_types_provided/2,
         to_json/2]).

-include_lib("webmachine/include/webmachine.hrl").

init(_Any) ->
    {ok, <<"{}">>}.

allowed_methods(Req, State) ->
    {['GET'], Req, State}.

content_types_provided(Req, State) ->
    {[{"application/json", to_json}], Req, State}.

to_json(Req, State) ->
    JobProcesses = pushy_job_state_sup:get_job_processes(),
    JobIds = [JobId || {JobId, _} <- JobProcesses],
    {jiffy:encode(JobIds), Req, State}. 
<commit_msg>format output from _status endpoint<commit_after>%% -*- erlang-indent-level: 4;indent-tabs-mode: nil; fill-column: 92 -*-
%% ex: ts=4 sw=4 et
%%% @author <NAME> <<EMAIL>>
%%% @copyright Copyright 2012-2012 Opscode Inc.
%%% @doc
%%% REST resource for monitoring status of pushy. Extracted from work done by <NAME> and <NAME> for erchef
%%% @end
-module(pushy_status_resource).

-export([init/1,
         allowed_methods/2,
         content_types_provided/2,
         to_json/2]).

-include_lib("webmachine/include/webmachine.hrl").

init(_Any) ->
    {ok, <<"{}">>}.

allowed_methods(Req, State) ->
    {['GET'], Req, State}.

content_types_provided(Req, State) ->
    {[{"application/json", to_json}], Req, State}.

to_json(Req, State) ->
    Json = {[{<<"status">>, <<"it's alive">>},
             {<<"job_processes">>, get_job_ids()}]},

    {jiffy:encode(Json), Req, State}. 

%% Private

get_job_ids() ->
    [JobId || {JobId, _} <- pushy_job_state_sup:get_job_processes()].
{'fraction_non_alphanumeric': 0.19426406926406928, 'fraction_numerical': 0.0183982683982684, 'mean_word_length': 3.8151041666666665, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3211428', 'n_tokens_mistral': 710, 'n_tokens_neox': 679, 'n_words': 143}