// Compiled by ClojureScript 1.10.520 {}
goog.provide('weathergen.progress');
goog.require('cljs.core');
goog.require('taoensso.timbre');
weathergen.progress._STAR_reporter_STAR_ = null;
weathergen.progress._STAR_current_step_STAR_ = null;

/**
 * @interface
 */
weathergen.progress.Reporter = function(){};

/**
 * Begins a new logical step in the reported sequence, a child of
 *  `parent` if non-nil. Returns a `Step` instance.
 */
weathergen.progress._start_step = (function weathergen$progress$_start_step(this$,step_name,parent){
if((((!((this$ == null)))) && ((!((this$.weathergen$progress$Reporter$_start_step$arity$3 == null)))))){
return this$.weathergen$progress$Reporter$_start_step$arity$3(this$,step_name,parent);
} else {
var x__4433__auto__ = (((this$ == null))?null:this$);
var m__4434__auto__ = (weathergen.progress._start_step[goog.typeOf(x__4433__auto__)]);
if((!((m__4434__auto__ == null)))){
return m__4434__auto__.call(null,this$,step_name,parent);
} else {
var m__4431__auto__ = (weathergen.progress._start_step["_"]);
if((!((m__4431__auto__ == null)))){
return m__4431__auto__.call(null,this$,step_name,parent);
} else {
throw cljs.core.missing_protocol.call(null,"Reporter.-start-step",this$);
}
}
}
});


/**
 * @interface
 */
weathergen.progress.Step = function(){};

/**
 * Reports that the step has succeeded. Implicitly closes the step.
 */
weathergen.progress._succeeded = (function weathergen$progress$_succeeded(this$){
if((((!((this$ == null)))) && ((!((this$.weathergen$progress$Step$_succeeded$arity$1 == null)))))){
return this$.weathergen$progress$Step$_succeeded$arity$1(this$);
} else {
var x__4433__auto__ = (((this$ == null))?null:this$);
var m__4434__auto__ = (weathergen.progress._succeeded[goog.typeOf(x__4433__auto__)]);
if((!((m__4434__auto__ == null)))){
return m__4434__auto__.call(null,this$);
} else {
var m__4431__auto__ = (weathergen.progress._succeeded["_"]);
if((!((m__4431__auto__ == null)))){
return m__4431__auto__.call(null,this$);
} else {
throw cljs.core.missing_protocol.call(null,"Step.-succeeded",this$);
}
}
}
});

/**
 * Reports that something nonfatal but of concern has happened.
 */
weathergen.progress._warn = (function weathergen$progress$_warn(this$,message){
if((((!((this$ == null)))) && ((!((this$.weathergen$progress$Step$_warn$arity$2 == null)))))){
return this$.weathergen$progress$Step$_warn$arity$2(this$,message);
} else {
var x__4433__auto__ = (((this$ == null))?null:this$);
var m__4434__auto__ = (weathergen.progress._warn[goog.typeOf(x__4433__auto__)]);
if((!((m__4434__auto__ == null)))){
return m__4434__auto__.call(null,this$,message);
} else {
var m__4431__auto__ = (weathergen.progress._warn["_"]);
if((!((m__4431__auto__ == null)))){
return m__4431__auto__.call(null,this$,message);
} else {
throw cljs.core.missing_protocol.call(null,"Step.-warn",this$);
}
}
}
});

/**
 * Reports that the step has failed. Implicitly closes the step.
 */
weathergen.progress._failed = (function weathergen$progress$_failed(this$,message){
if((((!((this$ == null)))) && ((!((this$.weathergen$progress$Step$_failed$arity$2 == null)))))){
return this$.weathergen$progress$Step$_failed$arity$2(this$,message);
} else {
var x__4433__auto__ = (((this$ == null))?null:this$);
var m__4434__auto__ = (weathergen.progress._failed[goog.typeOf(x__4433__auto__)]);
if((!((m__4434__auto__ == null)))){
return m__4434__auto__.call(null,this$,message);
} else {
var m__4431__auto__ = (weathergen.progress._failed["_"]);
if((!((m__4431__auto__ == null)))){
return m__4431__auto__.call(null,this$,message);
} else {
throw cljs.core.missing_protocol.call(null,"Step.-failed",this$);
}
}
}
});

/**
 * Returns this step's id, if any.
 */
weathergen.progress._id = (function weathergen$progress$_id(this$){
if((((!((this$ == null)))) && ((!((this$.weathergen$progress$Step$_id$arity$1 == null)))))){
return this$.weathergen$progress$Step$_id$arity$1(this$);
} else {
var x__4433__auto__ = (((this$ == null))?null:this$);
var m__4434__auto__ = (weathergen.progress._id[goog.typeOf(x__4433__auto__)]);
if((!((m__4434__auto__ == null)))){
return m__4434__auto__.call(null,this$);
} else {
var m__4431__auto__ = (weathergen.progress._id["_"]);
if((!((m__4431__auto__ == null)))){
return m__4431__auto__.call(null,this$);
} else {
throw cljs.core.missing_protocol.call(null,"Step.-id",this$);
}
}
}
});

/**
 * Reports progress via `*reporter*`, if bound.
 */
weathergen.progress.report = (function weathergen$progress$report(message){
if(cljs.core.truth_(weathergen.progress._STAR_reporter_STAR_)){
return weathergen.progress._STAR_reporter_STAR_.call(null,message);
} else {
return null;
}
});
/**
 * Reports that `step-name` has started. Returns a `Step` instance.
 */
weathergen.progress.start_step = (function weathergen$progress$start_step(step_name,parent){
if(cljs.core.truth_(weathergen.progress._STAR_reporter_STAR_)){
taoensso.timbre._log_BANG_.call(null,taoensso.timbre._STAR_config_STAR_,new cljs.core.Keyword(null,"info","info",-317069002),"weathergen.progress",null,38,new cljs.core.Keyword(null,"p","p",151049309),new cljs.core.Keyword(null,"auto","auto",-566279492),(new cljs.core.Delay((function (){
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, ["Starting ",step_name], null);
}),null)),null,-1668750334);

return weathergen.progress._start_step.call(null,weathergen.progress._STAR_reporter_STAR_,step_name,parent);
} else {
return null;
}
});
/**
 * Reports that step has succeeded. If no step is provided, uses
 *   `*current-step*`.
 */
weathergen.progress.step_succeeded = (function weathergen$progress$step_succeeded(var_args){
var G__28002 = arguments.length;
switch (G__28002) {
case 0:
return weathergen.progress.step_succeeded.cljs$core$IFn$_invoke$arity$0();

break;
case 1:
return weathergen.progress.step_succeeded.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));

break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));

}
});

weathergen.progress.step_succeeded.cljs$core$IFn$_invoke$arity$0 = (function (){
return weathergen.progress.step_succeeded.call(null,weathergen.progress._STAR_current_step_STAR_);
});

weathergen.progress.step_succeeded.cljs$core$IFn$_invoke$arity$1 = (function (step){
if(cljs.core.truth_(step)){
taoensso.timbre._log_BANG_.call(null,taoensso.timbre._STAR_config_STAR_,new cljs.core.Keyword(null,"info","info",-317069002),"weathergen.progress",null,47,new cljs.core.Keyword(null,"p","p",151049309),new cljs.core.Keyword(null,"auto","auto",-566279492),(new cljs.core.Delay((function (){
return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, ["Step Succeeded"], null);
}),null)),null,562939723);

return weathergen.progress._succeeded.call(null,step);
} else {
return null;
}
});

weathergen.progress.step_succeeded.cljs$lang$maxFixedArity = 1;

/**
 * Reports a warning against `step`, or `*current-step*` if one is not
 *   provided.
 */
weathergen.progress.step_warn = (function weathergen$progress$step_warn(var_args){
var G__28005 = arguments.length;
switch (G__28005) {
case 1:
return weathergen.progress.step_warn.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));

break;
case 2:
return weathergen.progress.step_warn.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));

break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));

}
});

weathergen.progress.step_warn.cljs$core$IFn$_invoke$arity$1 = (function (message){
return weathergen.progress.step_warn.call(null,weathergen.progress._STAR_current_step_STAR_,message);
});

weathergen.progress.step_warn.cljs$core$IFn$_invoke$arity$2 = (function (step,message){
if(cljs.core.truth_(step)){
taoensso.timbre._log_BANG_.call(null,taoensso.timbre._STAR_config_STAR_,new cljs.core.Keyword(null,"warn","warn",-436710552),"weathergen.progress",null,56,new cljs.core.Keyword(null,"p","p",151049309),new cljs.core.Keyword(null,"auto","auto",-566279492),(new cljs.core.Delay((function (){
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, ["Step warning",message], null);
}),null)),null,-340394417);

return weathergen.progress._warn.call(null,step,message);
} else {
return null;
}
});

weathergen.progress.step_warn.cljs$lang$maxFixedArity = 2;

/**
 * Reports that `step` has failed. Uses `*current-step*` if one is not
 *   provided.
 */
weathergen.progress.step_failed = (function weathergen$progress$step_failed(var_args){
var G__28008 = arguments.length;
switch (G__28008) {
case 1:
return weathergen.progress.step_failed.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));

break;
case 2:
return weathergen.progress.step_failed.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));

break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));

}
});

weathergen.progress.step_failed.cljs$core$IFn$_invoke$arity$1 = (function (message){
return weathergen.progress.step_failed.call(null,weathergen.progress._STAR_current_step_STAR_,message);
});

weathergen.progress.step_failed.cljs$core$IFn$_invoke$arity$2 = (function (step,message){
if(cljs.core.truth_(step)){
taoensso.timbre._log_BANG_.call(null,taoensso.timbre._STAR_config_STAR_,new cljs.core.Keyword(null,"error","error",-978969032),"weathergen.progress",null,65,new cljs.core.Keyword(null,"p","p",151049309),new cljs.core.Keyword(null,"auto","auto",-566279492),(new cljs.core.Delay((function (){
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, ["Step error",message], null);
}),null)),null,270841425);

return weathergen.progress._failed.call(null,step,message);
} else {
return null;
}
});

weathergen.progress.step_failed.cljs$lang$maxFixedArity = 2;

/**
 * Binds `*current-step*` to a new step calls `f`, a function of no
 *   arguments.
 */
weathergen.progress.with_step = (function weathergen$progress$with_step(step_name,f){
var step = weathergen.progress.start_step.call(null,step_name,weathergen.progress._STAR_current_step_STAR_);
var _STAR_current_step_STAR__orig_val__28010 = weathergen.progress._STAR_current_step_STAR_;
var _STAR_current_step_STAR__temp_val__28011 = step;
weathergen.progress._STAR_current_step_STAR_ = _STAR_current_step_STAR__temp_val__28011;

try{try{var val = f.call(null);
weathergen.progress.step_succeeded.call(null);

return val;
}catch (e28012){var x = e28012;
console.error("Caught error","propagated?",cljs.core._EQ_.call(null,new cljs.core.Keyword(null,"type","type",1174270348).cljs$core$IFn$_invoke$arity$1(cljs.core.ex_data.call(null,x)),new cljs.core.Keyword("weathergen.progress","propagated-error","weathergen.progress/propagated-error",1931683700)),":x",x,":data",cljs.core.ex_data.call(null,x));

weathergen.progress.step_failed.call(null,(function (){var map__28013 = cljs.core.ex_data.call(null,x);
var map__28013__$1 = (((((!((map__28013 == null))))?(((((map__28013.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__28013.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__28013):map__28013);
var type = cljs.core.get.call(null,map__28013__$1,new cljs.core.Keyword(null,"type","type",1174270348));
var omit_stack_trace_QMARK_ = cljs.core.get.call(null,map__28013__$1,new cljs.core.Keyword(null,"omit-stack-trace?","omit-stack-trace?",1080142229));
if(cljs.core._EQ_.call(null,type,new cljs.core.Keyword("weathergen.progress","propagated-error","weathergen.progress/propagated-error",1931683700))){
return null;
} else {
if(cljs.core.truth_(omit_stack_trace_QMARK_)){
return x.message;
} else {
return x.stack;

}
}
})());

throw cljs.core.ex_info.call(null,"Propagated error",new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"type","type",1174270348),new cljs.core.Keyword("weathergen.progress","propagated-error","weathergen.progress/propagated-error",1931683700)], null),x);
}}finally {weathergen.progress._STAR_current_step_STAR_ = _STAR_current_step_STAR__orig_val__28010;
}});
