Skip to content

Commit

Permalink
Merge pull request #34 from levibostian/strict-run-task-part-of-groups
Browse files Browse the repository at this point in the history
Do not allow running of PendingTasks if it's not the first task in a group.
  • Loading branch information
levibostian authored Apr 6, 2018
2 parents e8ab3f4 + b3d30ac commit e0e6332
Show file tree
Hide file tree
Showing 26 changed files with 291 additions and 36 deletions.
7 changes: 6 additions & 1 deletion Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ end

if git.modified_files.include? "build.gradle" or git.modified_files.include? "wendy/build.gradle"
warn "I see you edited a `build.gradle` file. Keep in mind that unless you are simply upgrading version numbers of libraries, that is ok. If you are adding dependencies, you may get your PR denied to keep the library slim."
end
end

# Generate the dokka docs and output the docs to the PR to assert there are no warnings.
`./bin/install_android_sdk.sh`
generateDocsOutput = `./gradlew dokka`
markdown "Output of generating docs: \n ```#{generateDocsOutput}```"
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import android.widget.Button
import android.widget.TextView
import com.curiosityio.wendyexample.R
import com.levibostian.wendy.WendyConfig
import com.levibostian.wendy.extension.addTaskStatusListenerForTask
import com.levibostian.wendy.extension.doesErrorExist
import com.levibostian.wendy.extension.isAbleToManuallyRun
import com.levibostian.wendy.service.PendingTask
import com.levibostian.wendy.service.Wendy
import java.text.SimpleDateFormat
Expand Down Expand Up @@ -48,12 +51,13 @@ class PendingTasksRecyclerViewAdapter(val data: List<PendingTask>) : RecyclerVie
holder.createdAtTextView.text = String.format("Created: %s", SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss z", Locale.ENGLISH).format(adapterItem.createdAt))

holder.statusTextView.text = "not running"
WendyConfig.addTaskStatusListenerForTask(adapterItem.taskId!!, holder.statusTextView)
adapterItem.addTaskStatusListenerForTask(holder.statusTextView)

holder.runTaskButton.visibility = if (adapterItem.isAbleToManuallyRun()) View.VISIBLE else View.GONE
holder.runTaskButton.setOnClickListener {
listener?.manuallyRunPressed(adapterItem)
}
holder.resolveErrorButton.visibility = if (Wendy.shared.doesErrorExist(adapterItem.taskId!!)) View.VISIBLE else View.GONE
holder.resolveErrorButton.visibility = if (adapterItem.doesErrorExist()) View.VISIBLE else View.GONE
holder.resolveErrorButton.setOnClickListener {
listener?.resolveErrorPressed(adapterItem)
}
Expand Down
1 change: 0 additions & 1 deletion bin/pr-tasks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

set -e

./gradlew dokka
./gradlew assembleDebug
./gradlew test
15 changes: 15 additions & 0 deletions docs/wendy/com.levibostian.wendy.extension/does-error-exist.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<HTML>
<HEAD>
<meta charset="UTF-8">
<title>doesErrorExist - 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.extension</a>&nbsp;/&nbsp;<a href="./does-error-exist.html">doesErrorExist</a><br/>
<br/>
<h1>doesErrorExist</h1>
<a name="com.levibostian.wendy.extension$doesErrorExist(com.levibostian.wendy.service.PendingTask)"></a>
<code><span class="keyword">fun </span><a href="../com.levibostian.wendy.service/-pending-task/index.html"><span class="identifier">PendingTask</span></a><span class="symbol">.</span><span class="identifier">doesErrorExist</span><span class="symbol">(</span><span class="symbol">)</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>Extension to <a href="../com.levibostian.wendy.service/-wendy/does-error-exist.html">Wendy.doesErrorExist</a> easily from a <a href="../com.levibostian.wendy.service/-pending-task/index.html">PendingTask</a> instance.</p>
</BODY>
</HTML>
18 changes: 18 additions & 0 deletions docs/wendy/com.levibostian.wendy.extension/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ <h3>Functions</h3>
</tr>
<tr>
<td>
<p><a href="does-error-exist.html">doesErrorExist</a></p>
</td>
<td>
<code><span class="keyword">fun </span><a href="../com.levibostian.wendy.service/-pending-task/index.html"><span class="identifier">PendingTask</span></a><span class="symbol">.</span><span class="identifier">doesErrorExist</span><span class="symbol">(</span><span class="symbol">)</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>Extension to <a href="../com.levibostian.wendy.service/-wendy/does-error-exist.html">Wendy.doesErrorExist</a> easily from a <a href="../com.levibostian.wendy.service/-pending-task/index.html">PendingTask</a> instance.</p>
</td>
</tr>
<tr>
<td>
<p><a href="get-latest-error.html">getLatestError</a></p>
</td>
<td>
Expand All @@ -40,6 +49,15 @@ <h3>Functions</h3>
</tr>
<tr>
<td>
<p><a href="is-able-to-manually-run.html">isAbleToManuallyRun</a></p>
</td>
<td>
<code><span class="keyword">fun </span><a href="../com.levibostian.wendy.service/-pending-task/index.html"><span class="identifier">PendingTask</span></a><span class="symbol">.</span><span class="identifier">isAbleToManuallyRun</span><span class="symbol">(</span><span class="symbol">)</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>Extension to <a href="../com.levibostian.wendy.service/-wendy/is-task-able-to-manually-run.html">Wendy.isTaskAbleToManuallyRun</a> easily from a <a href="../com.levibostian.wendy.service/-pending-task/index.html">PendingTask</a> instance.</p>
</td>
</tr>
<tr>
<td>
<p><a href="record-error.html">recordError</a></p>
</td>
<td>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<HTML>
<HEAD>
<meta charset="UTF-8">
<title>isAbleToManuallyRun - 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.extension</a>&nbsp;/&nbsp;<a href="./is-able-to-manually-run.html">isAbleToManuallyRun</a><br/>
<br/>
<h1>isAbleToManuallyRun</h1>
<a name="com.levibostian.wendy.extension$isAbleToManuallyRun(com.levibostian.wendy.service.PendingTask)"></a>
<code><span class="keyword">fun </span><a href="../com.levibostian.wendy.service/-pending-task/index.html"><span class="identifier">PendingTask</span></a><span class="symbol">.</span><span class="identifier">isAbleToManuallyRun</span><span class="symbol">(</span><span class="symbol">)</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>Extension to <a href="../com.levibostian.wendy.service/-wendy/is-task-able-to-manually-run.html">Wendy.isTaskAbleToManuallyRun</a> easily from a <a href="../com.levibostian.wendy.service/-pending-task/index.html">PendingTask</a> instance.</p>
</BODY>
</HTML>
36 changes: 27 additions & 9 deletions docs/wendy/com.levibostian.wendy.service/-pending-task/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,6 @@ <h3>Functions</h3>
<tbody>
<tr>
<td>
<p><a href="can-run-task.html">canRunTask</a></p>
</td>
<td>
<code><span class="keyword">open</span> <span class="keyword">fun </span><span class="identifier">canRunTask</span><span class="symbol">(</span><span class="symbol">)</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>Override this to dynamically set if this task is ready to run or not.</p>
</td>
</tr>
<tr>
<td>
<p><a href="equals.html">equals</a></p>
</td>
<td>
Expand All @@ -116,6 +107,15 @@ <h3>Functions</h3>
</tr>
<tr>
<td>
<p><a href="is-ready-to-run.html">isReadyToRun</a></p>
</td>
<td>
<code><span class="keyword">open</span> <span class="keyword">fun </span><span class="identifier">isReadyToRun</span><span class="symbol">(</span><span class="symbol">)</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>Override this to dynamically set if this task is ready to run or not.</p>
</td>
</tr>
<tr>
<td>
<p><a href="run-task.html">runTask</a></p>
</td>
<td>
Expand Down Expand Up @@ -148,6 +148,15 @@ <h3>Extension Functions</h3>
</tr>
<tr>
<td>
<p><a href="../../com.levibostian.wendy.extension/does-error-exist.html">doesErrorExist</a></p>
</td>
<td>
<code><span class="keyword">fun </span><a href="./index.html"><span class="identifier">PendingTask</span></a><span class="symbol">.</span><span class="identifier">doesErrorExist</span><span class="symbol">(</span><span class="symbol">)</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>Extension to <a href="../-wendy/does-error-exist.html">Wendy.doesErrorExist</a> easily from a <a href="./index.html">PendingTask</a> instance.</p>
</td>
</tr>
<tr>
<td>
<p><a href="../../com.levibostian.wendy.extension/get-latest-error.html">getLatestError</a></p>
</td>
<td>
Expand All @@ -166,6 +175,15 @@ <h3>Extension Functions</h3>
</tr>
<tr>
<td>
<p><a href="../../com.levibostian.wendy.extension/is-able-to-manually-run.html">isAbleToManuallyRun</a></p>
</td>
<td>
<code><span class="keyword">fun </span><a href="./index.html"><span class="identifier">PendingTask</span></a><span class="symbol">.</span><span class="identifier">isAbleToManuallyRun</span><span class="symbol">(</span><span class="symbol">)</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>Extension to <a href="../-wendy/is-task-able-to-manually-run.html">Wendy.isTaskAbleToManuallyRun</a> easily from a <a href="./index.html">PendingTask</a> instance.</p>
</td>
</tr>
<tr>
<td>
<p><a href="../../com.levibostian.wendy.extension/record-error.html">recordError</a></p>
</td>
<td>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<HTML>
<HEAD>
<meta charset="UTF-8">
<title>PendingTask.isReadyToRun - 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.service</a>&nbsp;/&nbsp;<a href="index.html">PendingTask</a>&nbsp;/&nbsp;<a href="./is-ready-to-run.html">isReadyToRun</a><br/>
<br/>
<h1>isReadyToRun</h1>
<a name="com.levibostian.wendy.service.PendingTask$isReadyToRun()"></a>
<code><span class="keyword">open</span> <span class="keyword">fun </span><span class="identifier">isReadyToRun</span><span class="symbol">(</span><span class="symbol">)</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>Override this to dynamically set if this task is ready to run or not.</p>
</BODY>
</HTML>
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ <h1>getLatestError</h1>
<h3>Parameters</h3>
<p><a name="taskId"></a>
<code>taskId</code> - The taskId of a <a href="../-pending-task/index.html">PendingTask</a> you may or may not have recorded an error for.</p>
<h3>Exceptions</h3>
<p><a name="IllegalArgumentException"></a>
<code>IllegalArgumentException</code> - If the <a href="../-pending-task/index.html">PendingTask</a> for the taskId provided does not exist.</p>
</BODY>
</HTML>
9 changes: 9 additions & 0 deletions docs/wendy/com.levibostian.wendy.service/-wendy/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ <h3>Functions</h3>
</tr>
<tr>
<td>
<p><a href="is-task-able-to-manually-run.html">isTaskAbleToManuallyRun</a></p>
</td>
<td>
<code><span class="keyword">fun </span><span class="identifier">isTaskAbleToManuallyRun</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$isTaskAbleToManuallyRun(kotlin.Long)/taskId">taskId</span><span class="symbol">:</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html"><span class="identifier">Long</span></a><span class="symbol">)</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>Tells you if a <a href="../-pending-task/index.html">PendingTask</a> is able to run yet or not.</p>
</td>
</tr>
<tr>
<td>
<p><a href="record-error.html">recordError</a></p>
</td>
<td>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<HTML>
<HEAD>
<meta charset="UTF-8">
<title>Wendy.isTaskAbleToManuallyRun - 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.service</a>&nbsp;/&nbsp;<a href="index.html">Wendy</a>&nbsp;/&nbsp;<a href="./is-task-able-to-manually-run.html">isTaskAbleToManuallyRun</a><br/>
<br/>
<h1>isTaskAbleToManuallyRun</h1>
<a name="com.levibostian.wendy.service.Wendy$isTaskAbleToManuallyRun(kotlin.Long)"></a>
<code><span class="keyword">fun </span><span class="identifier">isTaskAbleToManuallyRun</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$isTaskAbleToManuallyRun(kotlin.Long)/taskId">taskId</span><span class="symbol">:</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html"><span class="identifier">Long</span></a><span class="symbol">)</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>Tells you if a <a href="../-pending-task/index.html">PendingTask</a> is able to run yet or not.</p>
<p>To be able to run, all of these must be true:</p>
<ol><li>A <a href="../-pending-task/index.html">PendingTask</a> is not part of a group or it is the first task of a group.</li>
</ol>
<p>Call this before calling <a href="run-task.html">runTask</a> to avoid <a href="run-task.html">runTask</a> throwing an exception on you for it not being ready to run.</p>
<h3>Exceptions</h3>
<p><a name="IllegalArgumentException"></a>
<code>IllegalArgumentException</code> - If the <a href="../-pending-task/index.html">PendingTask</a> for the taskId provided does not exist.</p>
</BODY>
</HTML>
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ <h1>recordError</h1>
<a name="com.levibostian.wendy.service.Wendy$recordError(kotlin.Long, kotlin.String, kotlin.String)"></a>
<code><span class="keyword">fun </span><span class="identifier">recordError</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$recordError(kotlin.Long, kotlin.String, kotlin.String)/taskId">taskId</span><span class="symbol">:</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html"><span class="identifier">Long</span></a><span class="symbol">, </span><span class="identifier" id="com.levibostian.wendy.service.Wendy$recordError(kotlin.Long, kotlin.String, kotlin.String)/humanReadableErrorMessage">humanReadableErrorMessage</span><span class="symbol">:</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html"><span class="identifier">String</span></a><span class="symbol">?</span><span class="symbol">, </span><span class="identifier" id="com.levibostian.wendy.service.Wendy$recordError(kotlin.Long, kotlin.String, kotlin.String)/errorId">errorId</span><span class="symbol">:</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html"><span class="identifier">String</span></a><span class="symbol">?</span><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a></code>
<p>If you encounter an error while executing <a href="../-pending-task/run-task.html">PendingTask.runTask</a> in one of your <a href="../-pending-task/index.html">PendingTask</a>s, you can record it here to handle later in your app. This is usually used when your <a href="../-pending-task/index.html">PendingTask</a> encounters an error that requires the app user to fix (example: A string sent up to your API is too long. The user must shorten it up).</p>
<p><em>Note:</em> If you attempt to record an error using a <a href="record-error.html#com.levibostian.wendy.service.Wendy$recordError(kotlin.Long, kotlin.String, kotlin.String)/taskId">taskId</a> that does not exist, your request to record an error will be ignored.</p>
<h3>Parameters</h3>
<p><a name="taskId"></a>
<code>taskId</code> - The <a href="../-pending-task/task-id.html">PendingTask.taskId</a> for the <a href="../-pending-task/index.html">PendingTask</a> that encountered an error.</p>
<p><a name="humanReadableErrorMessage"></a>
<code>humanReadableErrorMessage</code> - A human readable error message that you may choose to show in the UI of your app. This message describes the error to the end user. Make sure they can understand it so they can resolve their issue.</p>
<p><a name="errorId"></a>
<code>errorId</code> - An ID identifying this error to Wendy. This exists for you, the developer. If and when the user of your app decides to fix the error, you can use this ID to determine what it was that was broken so you can show a UI to the user to fix the issue. Example: An <code>errorId</code> of "CreateGroceryItem" in your app could map to a UI in your app that shows the text of the entered grocery store item and the option for your user to edit it.</p>
<h3>Exceptions</h3>
<p><a name="IllegalArgumentException"></a>
<code>IllegalArgumentException</code> - If the <a href="../-pending-task/index.html">PendingTask</a> for the taskId provided does not exist. This should only happen if you (1) never added the <a href="../-pending-task/index.html">PendingTask</a> to Wendy in the first place or (2) the <a href="../-pending-task/index.html">PendingTask</a> ran, and was successful (then you should never have recorded an error in the first place).</p>
</BODY>
</HTML>
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ <h1>resolveError</h1>
<a name="com.levibostian.wendy.service.Wendy$resolveError(kotlin.Long)"></a>
<code><span class="keyword">fun </span><span class="identifier">resolveError</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$resolveError(kotlin.Long)/taskId">taskId</span><span class="symbol">:</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html"><span class="identifier">Long</span></a><span class="symbol">)</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>Mark a previously recorded error for a <a href="../-pending-task/index.html">PendingTask</a> as resolved.</p>
<p><em>Note:</em> If you attempt to resolve an error using a <a href="resolve-error.html#com.levibostian.wendy.service.Wendy$resolveError(kotlin.Long)/taskId">taskId</a> that does not exist, your request to record an error will be ignored.</p>
<p><em>Note:</em> If you attempt to resolve an error when an error does not exist in Wendy (because it has already been resolved or was never recorded) then the <a href="../../com.levibostian.wendy.listeners/-task-runner-listener/error-resolved.html">TaskRunnerListener.errorResolved</a> and <a href="../../com.levibostian.wendy.listeners/-pending-task-status-listener/error-resolved.html">PendingTaskStatusListener.errorResolved</a> will not be called.</p>
<p><em>Note:</em> The task runner will attempt to run your task after it has been resolved immediately. If the task belongs to a group, the task runner will attempt to run all the tasks in the group.</p>
<h3>Parameters</h3>
<p><a name="taskId"></a>
<code>taskId</code> - The taskId of a <a href="../-pending-task/index.html">PendingTask</a> previously recorded an error for.</p>
<h3>Exceptions</h3>
<p><a name="IllegalArgumentException"></a>
<code>IllegalArgumentException</code> - If the <a href="../-pending-task/index.html">PendingTask</a> for the taskId provided does not exist.</p>
<p><strong>Return</strong><br/>
If <a href="../-pending-task/index.html">PendingTask</a> had a previously recorded error and it has been marked as resolved now.</p>
<p><strong>See Also</strong><br/>
Expand Down
Loading

0 comments on commit e0e6332

Please sign in to comment.