<commit_before>-module(workorder_job_fail_handler).

-export([init/3]).
-export([allowed_methods/2]).
-export([content_types_accepted/2]).
-export([fail_work_order/2]).
-export([resource_exists/2]).
-export([service_available/2]).
-export([rest_init/2]).

-include("workorder.hrl").

-record(state, {
  conn,
  obj
}).

init(_Transport, _Req, []) ->
	{upgrade, protocol, cowboy_rest}.

rest_init(Req, _Opts) ->
  {ok, Req, #state{}}.

allowed_methods(Req, State) ->
    {[<<"PUT">>], Req, State}.

content_types_accepted(Req, State) ->
	{[{{<<"*">>, []}, fail_work_order}], Req, State}.	

service_available(Req, State) ->
  case riakou:take() of
    {error, _} ->
      {false, Req, State};
    Pid ->
      {true, Req, State#state{conn = Pid}}
  end.

resource_exists(Req, State = #state{conn = Pid}) ->
  {ID, Req2} = cowboy_req:binding(id, Req, <<>>),
  case riakc_pb_socket:get(Pid, ?JOBS_BUCKET, ID) of
    {error, _} ->
      {false, Req2, State};
    {ok, Obj} ->
      {true, Req2, State#state{obj = Obj}}
  end.

fail_work_order(Req, State) ->
	UpdatedObj = workorder_riak:set_binary_index("status",<<"Waiting">>, State#state.obj),
	riakc_pb_socket:put(State#state.conn, UpdatedObj),
	{ok, Req, State}.<commit_msg>fixes fail<commit_after>-module(workorder_job_fail_handler).

-export([init/3]).
-export([allowed_methods/2]).
-export([content_types_accepted/2]).
-export([fail_work_order/2]).
-export([resource_exists/2]).
-export([service_available/2]).
-export([rest_init/2]).

-include("workorder.hrl").

-record(state, {
  conn,
  obj
}).

init(_Transport, _Req, []) ->
	{upgrade, protocol, cowboy_rest}.

rest_init(Req, _Opts) ->
  {ok, Req, #state{}}.

allowed_methods(Req, State) ->
    {[<<"POST">>], Req, State}.

content_types_accepted(Req, State) ->
	{[{{<<"*">>, []}, fail_work_order}], Req, State}.	

service_available(Req, State) ->
  case riakou:take() of
    {error, _} ->
      {false, Req, State};
    Pid ->
      {true, Req, State#state{conn = Pid}}
  end.

resource_exists(Req, State = #state{conn = Pid}) ->
  {ID, Req2} = cowboy_req:binding(id, Req, <<>>),
  case riakc_pb_socket:get(Pid, ?JOBS_BUCKET, ID) of
    {error, _} ->
      {false, Req2, State};
    {ok, Obj} ->
      {true, Req2, State#state{obj = Obj}}
  end.

fail_work_order(Req, State) ->
	UpdatedObj = workorder_riak:set_binary_index("status",<<"Waiting">>, State#state.obj),
	riakc_pb_socket:put(State#state.conn, UpdatedObj),
	{ok, Req, State}.
{'fraction_non_alphanumeric': 0.21194762684124385, 'fraction_numerical': 0.008183306055646482, 'mean_word_length': 4.315217391304348, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 41, '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': '1061686', 'n_tokens_mistral': 999, 'n_tokens_neox': 990, 'n_words': 162}