# Ephemeral Jobs

**URL:** <https://discuss.elastic.co/t/ephemeral-jobs/202047>\
**Category:** APM\
**Created:** [October 2, 2019, 8:13pm UTC](https://discuss.elastic.co/t/ephemeral-jobs/202047 "2019-10-02T20:13:47Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonmoo-we](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@jasonmoo-we](https://discuss.elastic.co/u/jasonmoo-we)\
**Post date:** [October 2, 2019, 8:13pm UTC](https://discuss.elastic.co/t/ephemeral-jobs/202047/1 "2019-10-02T20:13:47Z")

</div>

Hi I'm just curious if the APM libraries can be used for short lived jobs (ie. a cron job that processes some entries in a queue and puts them in a database and exits). I haven't seen any special configuration for this. Do the APM libs flush before exit automatically or are they more suited for long-running daemons?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![beniwohli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/beniwohli/32/21256_2.png) [@beniwohli](https://discuss.elastic.co/u/beniwohli)\
**Post date:** [October 4, 2019, 11:43am UTC](https://discuss.elastic.co/t/ephemeral-jobs/202047/2 "2019-10-04T11:43:54Z")

</div>

Hey @jasonmoo-we

Excellent question! It depends a bit on which agent/language you use. Some agents, e.g. for Java and Python, will automatically flush the queue before the process exits (assuming a clean shutdown of the process). For other agents, like .net and Go, you will have to use the available APIs to manually flush the queue at the end of your program.

Hope this helps 🙂

---

<div class="post-metadata">

**Author:** ![jasonmoo-we](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@jasonmoo-we](https://discuss.elastic.co/u/jasonmoo-we)\
**Post date:** [October 4, 2019, 2:53pm UTC](https://discuss.elastic.co/t/ephemeral-jobs/202047/3 "2019-10-04T14:53:11Z")

</div>

Hey thanks for the response. Can you point me to any documentation where the manual flush is described, and which languages require it? Based on what you're saying it sounds like even the daemon processes should flush prior to shutdown.

---

<div class="post-metadata">

**Author:** ![jasonmoo-we](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@jasonmoo-we](https://discuss.elastic.co/u/jasonmoo-we)\
**Post date:** [October 8, 2019, 11:48pm UTC](https://discuss.elastic.co/t/ephemeral-jobs/202047/4 "2019-10-08T23:48:54Z")

</div>

@beniwohli is there anything you can share that references these ideas?

---

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [October 9, 2019, 6:20pm UTC](https://discuss.elastic.co/t/ephemeral-jobs/202047/5 "2019-10-09T18:20:35Z")

</div>

Hi @jasonmoo-we,

So, for Go, [here is](https://github.com/elastic/apm-agent-go/blob/master/tracer.go#L434) the `Flush` function with some documentation.

Also, [here](https://github.com/elastic/apm-agent-go/blob/master/tracer.go#L255) you can read a little bit more about this topic.

For .NET we don’t really have a public API yet to flush data manually, so the use case is not really supported at the moment in .NET. In .NET we have [some settings](https://www.elastic.co/guide/en/apm/agent/dotnet/current/config-reporter.html#config-flush-interval) that can help in this case, but those don’t really solve the problem.

Is there any specific language where we should follow up with more details?

---

<div class="post-metadata">

**Author:** ![jasonmoo-we](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@jasonmoo-we](https://discuss.elastic.co/u/jasonmoo-we)\
**Post date:** [October 9, 2019, 6:48pm UTC](https://discuss.elastic.co/t/ephemeral-jobs/202047/6 "2019-10-09T18:48:14Z")

</div>

Hey thanks @GregKalapos. I'm doing a survey for a deployment involving several languages so I'm trying to see how much difference there is between agents. Currently researching go and ruby.

From what I can see with the ruby agent, the worker (short lived jobs) does a flush before shutdown, but the rails server does not?  
And the go agent lib requires an explicit flush before exit in both worker and server applications.

---

<div class="post-metadata">

**Author:** ![jasonmoo-we](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@jasonmoo-we](https://discuss.elastic.co/u/jasonmoo-we)\
**Post date:** [October 9, 2019, 6:50pm UTC](https://discuss.elastic.co/t/ephemeral-jobs/202047/7 "2019-10-09T18:50:54Z")

</div>

If you could provide the flush behavior across all supported languages that would be ideal.

---

<div class="post-metadata">

**Author:** ![stephenbelanger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenbelanger/32/34880_2.png) [@stephenbelanger](https://discuss.elastic.co/u/stephenbelanger)\
**Post date:** [October 9, 2019, 7:07pm UTC](https://discuss.elastic.co/t/ephemeral-jobs/202047/8 "2019-10-09T19:07:18Z")

</div>

Node.js _tries_ to flush on process exit, but the process could be in an unknown or unexpected state at that point so there's no guarantees it would actually succeed.

---

<div class="post-metadata">

**Author:** ![mikker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikker/32/22118_2.png) [@mikker](https://discuss.elastic.co/u/mikker)\
**Post date:** [October 9, 2019, 8:08pm UTC](https://discuss.elastic.co/t/ephemeral-jobs/202047/9 "2019-10-09T20:08:36Z")

</div>

Hi @jasonmoo-we!

The Ruby agent _should_ empty its queue before exiting but there are no guarantees. The agent behaves the same with Rails request events as with events from background jobs. The `Worker` in the agent codebase is only related to the inner workings of the agent and doesn't relate directly to the concept of your app's worker processes.

What background job library are you using?

---

<div class="post-metadata">

**Author:** ![jasonmoo-we](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@jasonmoo-we](https://discuss.elastic.co/u/jasonmoo-we)\
**Post date:** [October 9, 2019, 8:29pm UTC](https://discuss.elastic.co/t/ephemeral-jobs/202047/10 "2019-10-09T20:29:38Z")

</div>

Cool. I'm looking at supporting arbitrary ruby applications that are able to instrument using the agent supplied.

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [October 10, 2019, 7:13am UTC](https://discuss.elastic.co/t/ephemeral-jobs/202047/11 "2019-10-10T07:13:27Z")

</div>

We don't have a manual flush API for the Java agent but we register a shutdown hook to flush on JVM shutdown.

---

<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:** [October 31, 2019, 3:13am UTC](https://discuss.elastic.co/t/ephemeral-jobs/202047/12 "2019-10-31T03:13:30Z")

</div>

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