Skip to content

Commit

Permalink
Merge pull request #31 from levibostian/strict-mode
Browse files Browse the repository at this point in the history
Strict mode
  • Loading branch information
levibostian authored Apr 6, 2018
2 parents ad30d00 + 6b02090 commit 10bc68f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ <h1>sharedInstance</h1>
<p>Get singleton instance of <a href="index.html">PendingTasks</a>.</p>
<h3>Exceptions</h3>
<p><a name="RuntimeException"></a>
<code>RuntimeException</code> - If you have not called <a href="#">PendingTasks.init</a> yet to initialize singleton instance.</p>
<code>RuntimeException</code> - If you have not called <a href="init.html">PendingTasks.Companion.init</a> yet to initialize singleton instance.</p>
</BODY>
</HTML>
9 changes: 9 additions & 0 deletions docs/wendy/com.levibostian.wendy/-wendy-config/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ <h3>Companion Object Properties</h3>
<p>The tag used when Wendy sends debug messages to the logcat.</p>
</td>
</tr>
<tr>
<td>
<p><a href="strict.html">strict</a></p>
</td>
<td>
<code><span class="keyword">var </span><span class="identifier">strict</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html"><span class="identifier">Boolean</span></a></code>
<p>Sets Wendy to strict mode or not. Strict mode helps while developing your app to find and fix potential issues while working with Wendy.</p>
</td>
</tr>
</tbody>
</table>
<h3>Companion Object Functions</h3>
Expand Down
18 changes: 18 additions & 0 deletions docs/wendy/com.levibostian.wendy/-wendy-config/strict.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<HTML>
<HEAD>
<meta charset="UTF-8">
<title>WendyConfig.strict - wendy</title>
<link rel="stylesheet" href="../../../style.css">
</HEAD>
<BODY>
<a href="../../index.html">wendy</a>&nbsp;/&nbsp;<a href="../index.html">com.levibostian.wendy</a>&nbsp;/&nbsp;<a href="index.html">WendyConfig</a>&nbsp;/&nbsp;<a href="./strict.html">strict</a><br/>
<br/>
<h1>strict</h1>
<a name="com.levibostian.wendy.WendyConfig.Companion$strict"></a>
<code><span class="keyword">var </span><span class="identifier">strict</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html"><span class="identifier">Boolean</span></a></code>
<p>Sets Wendy to strict mode or not. Strict mode helps while developing your app to find and fix potential issues while working with Wendy.</p>
<p>When strict is true, warnings throw errors instead of logging the warning to the console.
When strict is false, warnings get logged to the console and not crash your app instead.</p>
<p>Default: true</p>
</BODY>
</HTML>
2 changes: 2 additions & 0 deletions docs/wendy/index-outline.html
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
<a href="docs/wendy/index"><a href="com.levibostian.wendy/-wendy-config/automatically-run-tasks.html"><span class="keyword">var </span><span class="identifier">automaticallyRunTasks</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html"><span class="identifier">Boolean</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy/-wendy-config/debug.html"><span class="keyword">var </span><span class="identifier">debug</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html"><span class="identifier">Boolean</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy/-wendy-config/log-tag.html"><span class="keyword">var </span><span class="identifier">logTag</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html"><span class="identifier">String</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy/-wendy-config/strict.html"><span class="keyword">var </span><span class="identifier">strict</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html"><span class="identifier">Boolean</span></a></a></a><br/>
</BODY>
</HTML>
</ul>
Expand Down Expand Up @@ -266,6 +267,7 @@
<a href="docs/wendy/index"><a href="com.levibostian.wendy/-wendy-config/automatically-run-tasks.html"><span class="keyword">var </span><span class="identifier">automaticallyRunTasks</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html"><span class="identifier">Boolean</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy/-wendy-config/debug.html"><span class="keyword">var </span><span class="identifier">debug</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html"><span class="identifier">Boolean</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy/-wendy-config/log-tag.html"><span class="keyword">var </span><span class="identifier">logTag</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html"><span class="identifier">String</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy/-wendy-config/strict.html"><span class="keyword">var </span><span class="identifier">strict</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html"><span class="identifier">Boolean</span></a></a></a><br/>
</BODY>
</HTML>
</ul>
Expand Down
9 changes: 9 additions & 0 deletions wendy/src/main/java/com/levibostian/wendy/WendyConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ open class WendyConfig {
* *Note:* You can still have this property set to false and manually call [PendingTasks.runTasks] to run all tasks.
*/
var automaticallyRunTasks: Boolean = true
/**
* Sets Wendy to strict mode or not. Strict mode helps while developing your app to find and fix potential issues while working with Wendy.
*
* When strict is true, warnings throw errors instead of logging the warning to the console.
* When strict is false, warnings get logged to the console and not crash your app instead.
*
* Default: true
*/
var strict: Boolean = true
/**
* Turn on and off debug mode. This turns on and off Wendy sending messages to the logcat.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ internal class PendingTasksRunner(val context: Context,

when (result) {
PendingTaskResult.SUCCESSFUL -> {
if (PendingTasks.shared.doesErrorExist(taskToRun.task_id)) {
val errorMessage = "You returned ${PendingTaskResult.SUCCESSFUL} for running your ${PendingTask::class.java.simpleName}, but you have unresolved issues for task: $taskToRun. You should resolve the previously recorded error to Wendy, or return ${PendingTaskResult.FAILED}."
if (WendyConfig.strict) throw RuntimeException(errorMessage) else LogUtil.w(errorMessage)
}

LogUtil.d("Task: $taskToRun ran successful. Deleting it.")
pendingTasksManager.deleteTask(persistedPendingTaskId)
runJobResult = PendingTasksRunnerJobRunResult.SUCCESSFUL
Expand Down
6 changes: 6 additions & 0 deletions wendy/src/main/java/com/levibostian/wendy/util/LogUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ internal class LogUtil {
Log.d(WendyConfig.logTag, message)
}
}

fun w(message: String) {
if (WendyConfig.debug) {
Log.w(WendyConfig.logTag, message)
}
}
}
}

0 comments on commit 10bc68f

Please sign in to comment.