<commit_before>package com.garpr.android.sync

import com.firebase.jobdispatcher.JobParameters
import com.firebase.jobdispatcher.JobService
import com.garpr.android.App
import com.garpr.android.misc.NotificationsManager
import com.garpr.android.misc.RankingsNotificationsUtils
import com.garpr.android.misc.RankingsNotificationsUtils.PollStatus
import com.garpr.android.misc.RegionManager
import com.garpr.android.misc.Timber
import com.garpr.android.models.RankingsBundle
import com.garpr.android.networking.ApiListener
import com.garpr.android.networking.ServerApi
import javax.inject.Inject

class RankingsPollingJobService : JobService(), ApiListener<RankingsBundle> {

    private var mIsAlive: Boolean = true
    private var mPollStatus: PollStatus? = null

    @Inject
    lateinit protected var mNotificationsManager: NotificationsManager

    @Inject
    lateinit protected var mRankingsNotificationsUtils: RankingsNotificationsUtils

    @Inject
    lateinit protected var mRegionManager: RegionManager

    @Inject
    lateinit protected var mServerApi: ServerApi

    @Inject
    lateinit protected var mTimber: Timber


    companion object {
        private const val TAG = "RankingsPollingJobService"
    }

    init {
        App.get().appComponent.inject(this)
    }

    override fun failure(errorCode: Int) {
        mTimber.e(TAG, "failure fetching rankings ($errorCode)")
        mNotificationsManager.cancelAll()

        val pollStatus = mPollStatus

        if (pollStatus != null) {
            mPollStatus = pollStatus.copy(oldRankingsDate = pollStatus.oldRankingsDate,
                    proceed = pollStatus.proceed, retry = true)
        }
    }

    override val isAlive: Boolean
        get() = mIsAlive

    override fun onStartJob(job: JobParameters?): Boolean {
        val pollStatus = mRankingsNotificationsUtils.getPollStatus()
        mPollStatus = pollStatus

        return if (pollStatus.proceed) {
            mServerApi.getRankings(mRegionManager.getRegion(this), this)
            true
        } else {
            false
        }
    }

    override fun onStopJob(job: JobParameters?): Boolean {
        mIsAlive = false
        return mPollStatus?.retry == true
    }

    override fun success(`object`: RankingsBundle?) {
        val info = mRankingsNotificationsUtils.getNotificationInfo(mPollStatus, `object`)

        when (info) {
            RankingsNotificationsUtils.NotificationInfo.CANCEL -> {
                mNotificationsManager.cancelAll()
            }

            RankingsNotificationsUtils.NotificationInfo.NO_CHANGE -> {
                mTimber.d(TAG, "not changing any notifications")
            }

            RankingsNotificationsUtils.NotificationInfo.SHOW -> {
                mNotificationsManager.rankingsUpdated()
            }
        }
    }

}<commit_msg>properly note that the job has finished<commit_after>package com.garpr.android.sync

import com.firebase.jobdispatcher.JobParameters
import com.firebase.jobdispatcher.JobService
import com.garpr.android.App
import com.garpr.android.misc.NotificationsManager
import com.garpr.android.misc.RankingsNotificationsUtils
import com.garpr.android.misc.RankingsNotificationsUtils.PollStatus
import com.garpr.android.misc.RegionManager
import com.garpr.android.misc.Timber
import com.garpr.android.models.RankingsBundle
import com.garpr.android.networking.ApiListener
import com.garpr.android.networking.ServerApi
import javax.inject.Inject

class RankingsPollingJobService : JobService(), ApiListener<RankingsBundle> {

    private var mIsAlive: Boolean = true
    private var mJobParameters: JobParameters? = null
    private var mPollStatus: PollStatus? = null

    @Inject
    lateinit protected var mNotificationsManager: NotificationsManager

    @Inject
    lateinit protected var mRankingsNotificationsUtils: RankingsNotificationsUtils

    @Inject
    lateinit protected var mRegionManager: RegionManager

    @Inject
    lateinit protected var mServerApi: ServerApi

    @Inject
    lateinit protected var mTimber: Timber


    companion object {
        private const val TAG = "RankingsPollingJobService"
    }

    init {
        App.get().appComponent.inject(this)
    }

    override fun failure(errorCode: Int) {
        mTimber.e(TAG, "failure fetching rankings ($errorCode)")
        mNotificationsManager.cancelAll()

        val pollStatus = mPollStatus

        if (pollStatus != null) {
            mPollStatus = pollStatus.copy(oldRankingsDate = pollStatus.oldRankingsDate,
                    proceed = pollStatus.proceed, retry = true)
        }

        jobFinished(true)
    }

    override val isAlive: Boolean
        get() = mIsAlive

    private fun jobFinished(needsReschedule: Boolean) {
        mJobParameters?.let {
            jobFinished(it, needsReschedule)
        }
    }

    override fun onStartJob(job: JobParameters): Boolean {
        mJobParameters = job

        val pollStatus = mRankingsNotificationsUtils.getPollStatus()
        mPollStatus = pollStatus

        return if (pollStatus.proceed) {
            mServerApi.getRankings(mRegionManager.getRegion(this), this)
            true
        } else {
            false
        }
    }

    override fun onStopJob(job: JobParameters): Boolean {
        mIsAlive = false
        return mPollStatus?.retry == true
    }

    override fun success(`object`: RankingsBundle?) {
        val info = mRankingsNotificationsUtils.getNotificationInfo(mPollStatus, `object`)

        when (info) {
            RankingsNotificationsUtils.NotificationInfo.CANCEL -> {
                mNotificationsManager.cancelAll()
            }

            RankingsNotificationsUtils.NotificationInfo.NO_CHANGE -> {
                mTimber.d(TAG, "not changing any notifications")
            }

            RankingsNotificationsUtils.NotificationInfo.SHOW -> {
                mNotificationsManager.rankingsUpdated()
            }
        }

        jobFinished(false)
    }

}
{'fraction_non_alphanumeric': 0.07428475823991969, 'fraction_numerical': 0.0, 'mean_word_length': 2.8369704749679077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '423898', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1623, 'n_words': 334}