<commit_before>package ch.rmy.android.http_shortcuts.scheduling

import android.content.Context
import androidx.work.RxWorker
import androidx.work.WorkerParameters
import ch.rmy.android.framework.extensions.logException
import ch.rmy.android.http_shortcuts.activities.ExecuteActivity
import ch.rmy.android.http_shortcuts.data.RealmFactory
import ch.rmy.android.http_shortcuts.data.domains.pending_executions.PendingExecutionsRepository
import ch.rmy.android.http_shortcuts.data.models.PendingExecution
import io.reactivex.Completable
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers

class ExecutionWorker(private val context: Context, workerParams: WorkerParameters) :
    RxWorker(context, workerParams) {

    private val pendingExecutionsRepository = PendingExecutionsRepository()

    override fun createWork(): Single<Result> =
        Single.defer {
            val executionId = inputData.getString(INPUT_EXECUTION_ID) ?: return@defer Single.just(Result.failure())
            RealmFactory.init(applicationContext)
            runPendingExecution(context, executionId)
                .toSingleDefault(Result.success())
        }
            .onErrorReturn { error ->
                logException(error)
                Result.failure()
            }<commit_msg>Ignore NoSuchElementException when execution a pending shortcut, as it is expected that it might have been cancelled<commit_after>package ch.rmy.android.http_shortcuts.scheduling

import android.content.Context
import androidx.work.RxWorker
import androidx.work.WorkerParameters
import ch.rmy.android.framework.extensions.logException
import ch.rmy.android.http_shortcuts.activities.ExecuteActivity
import ch.rmy.android.http_shortcuts.data.RealmFactory
import ch.rmy.android.http_shortcuts.data.domains.pending_executions.PendingExecutionsRepository
import ch.rmy.android.http_shortcuts.data.models.PendingExecution
import io.reactivex.Completable
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers

class ExecutionWorker(private val context: Context, workerParams: WorkerParameters) :
    RxWorker(context, workerParams) {

    private val pendingExecutionsRepository = PendingExecutionsRepository()

    override fun createWork(): Single<Result> =
        Single.defer {
            val executionId = inputData.getString(INPUT_EXECUTION_ID) ?: return@defer Single.just(Result.failure())
            RealmFactory.init(applicationContext)
            runPendingExecution(context, executionId)
                .toSingleDefault(Result.success())
        }
            .onErrorResumeNext { error ->
                if (error is NoSuchElementException) {
                    Single.just(Result.success())
                } else {
                    logException(error)
                    Single.just(Result.failure())
                }
            }
{'fraction_non_alphanumeric': 0.079002079002079, 'fraction_numerical': 0.0, 'mean_word_length': 3.5971337579617835, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '6725306', 'n_tokens_mistral': 778, 'n_tokens_neox': 743, 'n_words': 132}