Skip to content

Instantly share code, notes, and snippets.

View austermann's full-sized avatar

Michael Austermann austermann

View GitHub Profile
@GrigorievNick
GrigorievNick / GracefulStopOnShutdownListener.scala
Last active April 10, 2024 14:01
Spark Structure Streaming GraceFullShutdown on Sigterm. Sigterm will not interrupt currently running batch, but due to asynс nature of SparkQueryListner.onProgres method, can interrupt next batch during first few moments.
import org.apache.hadoop.util.ShutdownHookManager
import org.apache.spark.sql.streaming.StreamingQueryListener
import org.apache.spark.sql.streaming.StreamingQueryManager
import org.slf4j.LoggerFactory
import java.util.UUID
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.SynchronousQueue
import java.util.concurrent.TimeUnit