Skip to content

Commit

Permalink
Modify Service API to be used directly by the handlers (#11587)
Browse files Browse the repository at this point in the history
  • Loading branch information
malikdiarra committed Apr 24, 2024
1 parent 64fb7fe commit 5e8570b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package io.airbyte.data.services

import io.airbyte.data.repositories.entities.ConnectionTimelineEvent
import io.airbyte.data.services.shared.ConnectionEvent
import java.util.UUID

interface ConnectionTimelineEventService {
fun writeEvent(event: ConnectionTimelineEvent): ConnectionTimelineEvent
fun writeEvent(
connectionId: UUID,
event: ConnectionEvent,
): ConnectionTimelineEvent
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
package io.airbyte.data.services.impls.data

import com.fasterxml.jackson.databind.ObjectMapper
import io.airbyte.data.repositories.ConnectionTimelineEventRepository
import io.airbyte.data.repositories.entities.ConnectionTimelineEvent
import io.airbyte.data.services.ConnectionTimelineEventService
import io.airbyte.data.services.shared.ConnectionEvent
import jakarta.inject.Singleton
import java.util.UUID

@Singleton
class ConnectionTimelineEventServiceImpl(private val repository: ConnectionTimelineEventRepository) : ConnectionTimelineEventService {
override fun writeEvent(event: ConnectionTimelineEvent): ConnectionTimelineEvent {
override fun writeEvent(
connectionId: UUID,
connectionEvent: ConnectionEvent,
): ConnectionTimelineEvent {
val serializedEvent = MAPPER.writeValueAsString(connectionEvent)
val event =
ConnectionTimelineEvent(null, connectionId, connectionEvent.getUserId(), connectionEvent.getEventType().toString(), serializedEvent, null)
return repository.save(event)
}

companion object {
private val MAPPER = ObjectMapper()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.airbyte.data.services.shared

import java.util.UUID

interface ConnectionEvent {
enum class Type {
SYNC_SUCCEEDED,
}

fun getUserId(): UUID? {
return null
}

fun getEventType(): Type
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.airbyte.data.services.shared

class SyncSucceededEvent(
private val jobId: Long,
private val startTimeEpochSeconds: Long,
private val endTimeEpochSeconds: Long,
private val bytesLoaded: Long,
private val recordsLoaded: Long,
private val attemptsCount: Int,
) : ConnectionEvent {
fun startTimeEpochSeconds(): Long {
return this.startTimeEpochSeconds
}

fun endTimeEpochSeconds(): Long {
return endTimeEpochSeconds
}

fun getJobId(): Long {
return jobId
}

fun getBytesLoaded(): Long {
return bytesLoaded
}

fun getRecordsLoaded(): Long {
return recordsLoaded
}

fun getAttemptsCount(): Int {
return attemptsCount
}

override fun getEventType(): ConnectionEvent.Type {
return ConnectionEvent.Type.SYNC_SUCCEEDED
}
}

0 comments on commit 5e8570b

Please sign in to comment.