Skip to content

Instantly share code, notes, and snippets.

@Malinskiy
Last active March 7, 2019 16:23
Show Gist options
  • Save Malinskiy/a624bc73218f9ba2fe0f0e29beb7d262 to your computer and use it in GitHub Desktop.
Save Malinskiy/a624bc73218f9ba2fe0f0e29beb7d262 to your computer and use it in GitHub Desktop.
class DevicePoolActor(private val poolId: DevicePoolId,
private val configuration: Configuration,
analytics: Analytics,
tests: Collection<Test>,
private val progressReporter: ProgressReporter,
parent: Job,
context: CoroutineContext) :
Actor<DevicePoolMessage>(parent = parent, context = context) {
override suspend fun receive(msg: DevicePoolMessage) {
when (msg) {
is DevicePoolMessage.FromScheduler.AddDevice -> addDevice(msg.device)
is DevicePoolMessage.FromScheduler.RemoveDevice -> removeDevice(msg.device)
is DevicePoolMessage.FromScheduler.Terminate -> terminate()
is DevicePoolMessage.FromDevice.IsReady -> deviceReady(msg)
is DevicePoolMessage.FromDevice.CompletedTestBatch -> deviceCompleted(msg.device, msg.results)
is DevicePoolMessage.FromDevice.ReturnTestBatch -> deviceReturnedTestBatch(msg.device, msg.batch)
is DevicePoolMessage.FromQueue.Notify -> notifyDevices()
is DevicePoolMessage.FromQueue.Terminated -> onQueueTerminated()
is DevicePoolMessage.FromQueue.ExecuteBatch -> executeBatch(msg.device, msg.batch)
}
}
private suspend fun deviceCompleted(device: Device, results: TestBatchResults) {
queue.send(QueueMessage.Completed(device.toDeviceInfo(), results))
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment