# Ruby filter to execute code only once

**URL:** <https://discuss.elastic.co/t/ruby-filter-to-execute-code-only-once/193243>\
**Category:** Logstash\
**Created:** [August 1, 2019, 3:46am UTC](https://discuss.elastic.co/t/ruby-filter-to-execute-code-only-once/193243 "2019-08-01T03:46:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [August 1, 2019, 3:46am UTC](https://discuss.elastic.co/t/ruby-filter-to-execute-code-only-once/193243/1 "2019-08-01T03:46:39Z")

</div>

Hi All

I have a scenario where I am using Ruby filter and I want to execute the code only once after reading the input. Basically after executing this code it should come out to output and should not process further

I tried Ruby 'init' which works perfectly well, but it works only when pipeline starts.

My pipeline will keep running on daily basis and input will have schedule that will read input data and execute the Ruby filter code only once and give it to output.

Example : I have 10 records from input  
1 record from Ruby filter (hard coded record)

so 11 records in output

Is there any way I can Ruby filter once and exit?

---

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [August 1, 2019, 12:14pm UTC](https://discuss.elastic.co/t/ruby-filter-to-execute-code-only-once/193243/2 "2019-08-01T12:14:06Z")

</div>

Anyone has tips around it?

Thanks for reading my problem

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 29, 2019, 12:14pm UTC](https://discuss.elastic.co/t/ruby-filter-to-execute-code-only-once/193243/3 "2019-08-29T12:14:23Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
