Skip to content

Instantly share code, notes, and snippets.

View geomagilles's full-sized avatar

Gilles Barbier geomagilles

View GitHub Profile
@geomagilles
geomagilles / TaskEngineWorker.kt
Last active December 15, 2020 11:19
Building Workers With Coroutines
typealias TaskEngineMessageToProcess = MessageToProcess<TaskEngineMessage>
fun CoroutineScope.startPulsarTaskEngineWorker(
taskEngineConsumer: Consumer<TaskEngineEnvelope>,
taskEngine: TaskEngine,
logChannel: SendChannel<TaskEngineMessageToProcess>?,
enginesNumber: Int
) = launch(Dispatchers.IO) {
val taskInputChannel = Channel<TaskEngineMessageToProcess>()
@geomagilles
geomagilles / TaskEngineEnvelope.kt
Last active December 15, 2020 10:25
TaskEngineEnvelope
@Serializable
data class TaskEngineEnvelope(
val taskId: TaskId,
val type: TaskEngineMessageType,
val dispatchTask: DispatchTask? = null,
val cancelTask: CancelTask? = null,
val taskCanceled: TaskCanceled? = null,
val taskCompleted: TaskCompleted? = null,
) {
init {
@geomagilles
geomagilles / TaskEngineMessage.kt
Created December 15, 2020 10:14
TaskEngineMessages
@Serializable
sealed class TaskEngineMessage() {
abstract val taskId: TaskId
}
@Serializable
data class DispatchTask(
override val taskId: TaskId,
val taskName: TaskName,
val methodName: MethodName,
@geomagilles
geomagilles / kotlinPulsarConsumerProducer.kt
Last active December 14, 2020 21:35
Building Pulsar Producer<T> and Consumer<T> in kotlin using native serialization
import com.github.avrokotlin.avro4k.Avro
import com.github.avrokotlin.avro4k.io.AvroEncodeFormat
import io.infinitic.common.tasks.executors.messages.RunTask
import kotlinx.serialization.KSerializer
import org.apache.avro.file.SeekableByteArrayInput
import org.apache.avro.generic.GenericDatumReader
import org.apache.avro.generic.GenericRecord
import org.apache.avro.io.DecoderFactory
import org.apache.pulsar.client.api.Consumer
import org.apache.pulsar.client.api.Producer
@geomagilles
geomagilles / hello_world.js
Created November 19, 2019 15:54
Hello World Zenaton
function hello(name) {
console.log('Hello world ' + name)
}
@geomagilles
geomagilles / hello_world.js
Created November 19, 2019 15:53
Hello World Zenaton
function hello(name) {
console.log('Hello world ' + name)
}
const { Workflow, Task, Wait } = require("zenaton");
// start child workflow
let StartChildWorkflow = Task("StartChildWorkflow", {
init(users, id) {
this.users = users;
this.id = id;
},
handle: async function() {
await new ChildWorkflow(this.user, this.id).dispatch()
<?php
use Zenaton\Interfaces\WorkflowInterface;
use Zenaton\Tasks\Wait;
use Zenaton\Traits\Zenatonable;
class RequestManagementWorkflow implements WorkflowInterface
{
use Zenatonable;
<?php
...
public function handle()
{
...
// if no response received in 3 days
if (0 == count($this->quotations)) {
<?php
...
public function handle()
{
...
// wait for at most 3 providers quotation, 3 days maximum
$event = (new Wait(ProvidersQuotationGatheredEvent::class))->days(3)->execute();