Friday, 29 January 2021

How to make the .proto definition files visible in Android view in Android Studio (4.2)?

When using protobuf definitions in my gradle projects, protoc works as expected. Everything builds as it is supposed to do. However, when working in the Android view (I mean View->Project->Android), the definition file doesn't show up. On the contrary, it is visible from View->Project->Project. There I can find the my protobuf definition files as expected in e.g. app/src/main/proto.

Sources are defined in my build.gradle like this:

android {
    sourceSets {
        main {
            proto {
                srcDir '../src/main/proto'
            }
        }
    }
}

What do I have to do to make the proto source files visible in the Android view?



from How to make the .proto definition files visible in Android view in Android Studio (4.2)?

How to observer Android Worker progress for chained workers

My current Android application employs Workers for its background processes.

api "androidx.work:work-runtime:2.4.0"
api "androidx.work:work-runtime-ktx:2.4.0"

I chain multiple workers together and would like to report on each workers progress

I have an issue in that I only get a single progress update from each worker

when each worker publish progress twice as follows:-

override suspend fun doWork(): Result = coroutineScope { val startTime: Long = System.nanoTime()

    val progressName = "$PROGRESS_PRE_PIX$workerName"

    withContext(Dispatchers.IO) {
        try {
            setProgressAsync(workDataOf(progressName to 0))
            doActualWork()
        } finally {
            setProgressAsync(workDataOf(progressName to 100))
        }
    }
}

I observeForever the workInfos from my chained workers continuation as shown here :-

 workContinuation.workInfosLiveData.observeForever { workInfos ->
                workInfos.forEach { workInfo ->
                    Timber.e("xoox - $workInfo")
                }
            }

I have verbose worker logging configured and each worker generates these log entries

2021-01-26 13:30:15.956  D/WM-WorkProgressUpdater: Updating progress for c9ef0d9a-f253-4403-944d-b9afb1a043ef (Data {PROGRESS-MyWorker : 0, })
2021-01-26 13:30:16.151  D/WM-WorkProgressUpdater: Updating progress for c9ef0d9a-f253-4403-944d-b9afb1a043ef (Data {PROGRESS-MyWorker : 100, })

however my observer only logs out 1 entry

xoox - WorkInfo{mId='70251d4e-882d-4ab8-946f-20cfba2d767a', mState=RUNNING, mOutputData=Data {}, mTags=[com.mendeley.refmanager.background.work.worker.GroupWorker], mProgress=Data {PROGRESS-MyWorker : 0, }}

What am I doing wrong?

Why dont I see the setProgressAsync(workDataOf(progressName to 100)) logged?



from How to observer Android Worker progress for chained workers

How to save storage in python crawler (common strings)

I have a python3 crawler that connect to target sites and saves all html and resources. Although I compress with gzip before saving it consumes too much space and I usually reach my configured space limit before less than half of website pages are crawled.

The point is that all pages of the same website have a lot of common strings (there are even websites that include resources like css in all html pages instead linking then). Then my idea is saving the common strings for the same website. I thought this kind of optimization would be documented, but I didn't found anything about this.

Although I have this idea, I don't know how to implement this kind of algorithm. Any help would be appreciated.



from How to save storage in python crawler (common strings)