package Ġcom . bre un inger . boot . jobs . repository . cleanup Ċ Ċ import Ġcom . bre un inger . boot . jobs . autoconfigure . Jobs Properties Ċ import Ġcom . bre un inger . boot . jobs . domain . Job Execution . Status . OK Ċ import Ġcom . bre un inger . boot . jobs . service . Job Execution Service Ċ import Ġio . micro meter . core . annotation . Timed Ċ import Ġorg . springframework . scheduling . annotation . Scheduled Ċ import Ġorg . springframework . stereotype . Component Ċ Ċ @ Component Ċ class ĠKeep Last Job Execution s Cleanup Strategy ( ĊĠ Ġprivate Ġval Ġjob Execution Service : ĠJob Execution Service , ĊĠ Ġprivate Ġval Ġjobs Properties : ĠJobs Properties Ċ ) Ġ{ ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĊĠĠĠ Ġprivate Ġconst Ġval ĠK EE P _ LAST _ JOB _ EXEC UTION S _ CLEAN UP _ FIXED _ RATE Ġ= Ġ 1 L Ġ* Ġ 6 0 L Ġ* Ġ 1 0 0 0 L ĊĠ Ġ} ĊĊĠ Ġ@ Timed (" com . bre un inger . boot . jobs . repository . cleanup . Keep Last Job Execution s Cleanup Strategy . clean Up ", Ġlong Task Ġ= Ġtrue ) ĊĠ Ġ@ Scheduled ( initial Delay Ġ= Ġ 0 , Ġfixed Rate Ġ= ĠK EE P _ LAST _ JOB _ EXEC UTION S _ CLEAN UP _ FIXED _ RATE ) ĊĠ Ġfun Ġclean Up () Ġ{ ĊĠĠĠ Ġjob Execution Service . findAll Ignore Messages () ĊĠĠĠĠĠ Ġ. sorted By Descending Ġ{ Ġit . started Ġ} ĊĠĠĠĠĠ Ġ. groupBy Ġ{ Ġit . jobId Ġ} ĊĠĠĠĠĠ Ġ. flatMap Ġ{ Ġjob To Job Execution s Ġ-> ĊĠĠĠĠĠĠĠ Ġval Ġlast Ok Execution Ġ= Ġjob To Job Execution s . value . find Ġ{ Ġit . has Stopped () Ġ&& Ġit . status Ġ== ĠOK Ġ} ĊĠĠĠĠĠĠĠ Ġjob To Job Execution s . value ĊĠĠĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġit . has Stopped () Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ. drop ( jobs Properties . cleanup . numberOf Job Execution sTo Keep ) ĊĠĠĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġit Ġ!= Ġlast Ok Execution Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ. forEach Ġ{ Ġjob Execution Service . remove ( it ) Ġ} ĊĠ Ġ} Ċ } Ċ