faust icon indicating copy to clipboard operation
faust copied to clipboard

include agent stopper

Open zerafachris opened this issue 2 years ago • 1 comments

Note: Before submitting this pull request, please review our contributing guidelines.

Description

This includes an agent_stopper functionality that kills the main agent without producing exit status 0 Fixes https://github.com/faust-streaming/faust/issues/324

Usage

use this module as await agent_stopper(app)

zerafachris avatar Jul 26 '22 08:07 zerafachris

Change app.loop.stop() to app._crash() and I think we're good 🙂

wbarnha avatar Aug 12 '22 01:08 wbarnha

Codecov Report

Base: 94.39% // Head: 94.29% // Decreases project coverage by -0.09% :warning:

Coverage data is based on head (4f63de9) compared to base (ce53c40). Patch coverage: 0.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #329      +/-   ##
==========================================
- Coverage   94.39%   94.29%   -0.10%     
==========================================
  Files         100      101       +1     
  Lines       10915    10921       +6     
  Branches     1531     1531              
==========================================
- Hits        10303    10298       -5     
- Misses        534      544      +10     
- Partials       78       79       +1     
Impacted Files Coverage Δ
faust/utils/agent_stopper.py 0.00% <0.00%> (ø)
faust/web/views.py 97.60% <0.00%> (-2.41%) :arrow_down:
faust/streams.py 96.06% <0.00%> (-0.19%) :arrow_down:
faust/topics.py 100.00% <0.00%> (ø)
faust/models/typing.py 95.30% <0.00%> (ø)
faust/stores/rocksdb.py 89.45% <0.00%> (ø)
faust/web/cache/cache.py 100.00% <0.00%> (ø)
faust/stores/aerospike.py 76.12% <0.00%> (ø)
faust/tables/globaltable.py 100.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov-commenter avatar Sep 22 '22 15:09 codecov-commenter

@wbarnha @patkivikram I tested out app._crash(), and I think this is not producing the expected behaviour. I tried failing an app using 'raise ValueError('Force fail')' and the agent goes into an infinite loop trying to restart. I think it should be reverted to app.loop.stop().

This is the log when using app.loop.stop().

[2022-10-21 11:28:44,522] [28723] [INFO] [^DSWorker]: Ready 
[2022-10-21 11:28:47,442] [28723] [ERROR] Traceback (most recent call last):
  File "/Users/christopher.zerafa/Library/CloudStorage/[email protected]/My Drive/repos/ds-rg-angel/src/proj/modules/agents.py", line 35, in predict
    raise ValueError('Force fail')
ValueError: Force fail
 
[2022-10-21 11:28:47,442] [28723] [WARNING] Closing application 
[2022-10-21 11:28:47,443] [28723] [ERROR] [^DSWorker]: Error: RuntimeError('Event loop stopped before Future completed.') 
Traceback (most recent call last):
  File "/usr/local/Caskroom/miniforge/base/envs/ds-rg-angel/lib/python3.9/site-packages/mode/worker.py", line 279, in execute_from_commandline
    self.loop.run_until_complete(self._starting_fut)
  File "/usr/local/Caskroom/miniforge/base/envs/ds-rg-angel/lib/python3.9/asyncio/base_events.py", line 645, in run_until_complete
    raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
[2022-10-21 11:28:47,463] [28723] [INFO] [^DSWorker]: Stopping... 
[2022-10-21 11:28:47,465] [28723] [INFO] [^-App]: Stopping... 
[2022-10-21 11:28:47,466] [28723] [INFO] [^---Fetcher]: Stopping... 
[2022-10-21 11:28:47,468] [28723] [INFO] [^--TableManager]: Stopping... 
[2022-10-21 11:28:47,468] [28723] [INFO] [^---Fetcher]: Stopping... 
[2022-10-21 11:28:47,469] [28723] [INFO] [^---Recovery]: Stopping... 
[2022-10-21 11:28:47,470] [28723] [INFO] [^-App]: Flush producer buffer... 
[2022-10-21 11:28:47,472] [28723] [INFO] [^---Conductor]: Stopping... 
[2022-10-21 11:28:47,473] [28723] [INFO] [^--AgentManager]: Stopping... 
[2022-10-21 11:28:47,474] [28723] [INFO] [^---Agent: proj.modules.agents.predict]: Stopping... 
[2022-10-21 11:28:47,474] [28723] [INFO] [^----OneForOneSupervisor: (1@0x15964d970)]: Stopping... 
[2022-10-21 11:28:47,477] [28723] [INFO] [^--ReplyConsumer]: Stopping... 
[2022-10-21 11:28:47,478] [28723] [INFO] [^--LeaderAssignor]: Stopping... 
[2022-10-21 11:28:47,479] [28723] [INFO] [^--Consumer]: Stopping... 
[2022-10-21 11:28:47,480] [28723] [INFO] [^---AIOKafkaConsumerThread]: Stopping... 
[2022-10-21 11:28:47,543] [28723] [INFO] LeaveGroup request succeeded 
[2022-10-21 11:28:47,552] [28723] [INFO] [^--Web]: Stopping... 
[2022-10-21 11:28:47,552] [28723] [INFO] [^---ServerThread]: Stopping... 
[2022-10-21 11:28:47,554] [28723] [INFO] [^--Web]: Cleanup 
[2022-10-21 11:28:47,556] [28723] [INFO] [^--CacheBackend]: Stopping... 
[2022-10-21 11:28:47,557] [28723] [INFO] [^--Producer]: Stopping... 
[2022-10-21 11:28:47,559] [28723] [INFO] [^---ProducerBuffer]: Stopping... 
[2022-10-21 11:28:47,561] [28723] [INFO] [^--PrometheusMonitor]: Stopping... 
[2022-10-21 11:28:47,565] [28723] [INFO] [^DSWorker]: Gathering service tasks... 
[2022-10-21 11:28:47,565] [28723] [INFO] [^DSWorker]: Gathering all futures... 
[2022-10-21 11:28:49,577] [28723] [INFO] [^DSWorker]: Closing event loop 

This is the log when using app._crash():

[2022-10-21 11:32:24,369] [30152] [INFO] [^DSWorker]: Ready 
[2022-10-21 11:32:27,222] [30152] [ERROR] [^----Agent*: proj.modules.agents.predict]: Crashed reason=TypeError("'module' object is not callable") 
Traceback (most recent call last):
  File "/Users/christopher.zerafa/Library/CloudStorage/[email protected]/My Drive/repos/ds-rg-angel/src/proj/modules/agents.py", line 36, in predict
    raise ValueError('Force fail')
ValueError: Force fail

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Caskroom/miniforge/base/envs/ds-rg-angel/lib/python3.9/site-packages/faust/agents/agent.py", line 674, in _execute_actor
    await coro
  File "/usr/local/Caskroom/miniforge/base/envs/ds-rg-angel/lib/python3.9/site-packages/faust/agents/agent.py", line 696, in _slurp
    async for value in it:
  File "/Users/christopher.zerafa/Library/CloudStorage/[email protected]/My Drive/repos/ds-rg-angel/src/proj/modules/agents.py", line 101, in predict
    await agent_stopper(app)
TypeError: 'module' object is not callable
[2022-10-21 11:32:27,227] [30152] [INFO] [^----OneForOneSupervisor: (1@0x107c5c7c0)]: Restarting dead <Agent*: proj.modules.agents.predict>! Last crash reason: TypeError("'module' object is not callable") 
NoneType: None
[2022-10-21 11:32:27,464] [30152] [ERROR] [^----Agent*: proj.modules.agents.predict]: Crashed reason=TypeError("'module' object is not callable") 
Traceback (most recent call last):
  File "/Users/christopher.zerafa/Library/CloudStorage/[email protected]/My Drive/repos/ds-rg-angel/src/proj/modules/agents.py", line 36, in predict
    raise ValueError('Force fail')
ValueError: Force fail

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Caskroom/miniforge/base/envs/ds-rg-angel/lib/python3.9/site-packages/faust/agents/agent.py", line 674, in _execute_actor
    await coro
  File "/usr/local/Caskroom/miniforge/base/envs/ds-rg-angel/lib/python3.9/site-packages/faust/agents/agent.py", line 696, in _slurp
    async for value in it:
  File "/Users/christopher.zerafa/Library/CloudStorage/[email protected]/My Drive/repos/ds-rg-angel/src/proj/modules/agents.py", line 101, in predict
    await agent_stopper(app)
TypeError: 'module' object is not callable
[2022-10-21 11:32:32,468] [30152] [INFO] [^----OneForOneSupervisor: (1@0x107c5c7c0)]: Restarting dead <Agent*: proj.modules.agents.predict>! Last crash reason: TypeError("'module' object is not callable") 
NoneType: None
[2022-10-21 11:32:32,961] [30152] [ERROR] [^----Agent*: proj.modules.agents.predict]: Crashed reason=TypeError("'module' object is not callable") 
Traceback (most recent call last):
  File "/Users/christopher.zerafa/Library/CloudStorage/[email protected]/My Drive/repos/ds-rg-angel/src/proj/modules/agents.py", line 36, in predict
    raise ValueError('Force fail')
ValueError: Force fail

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Caskroom/miniforge/base/envs/ds-rg-angel/lib/python3.9/site-packages/faust/agents/agent.py", line 674, in _execute_actor
    await coro
  File "/usr/local/Caskroom/miniforge/base/envs/ds-rg-angel/lib/python3.9/site-packages/faust/agents/agent.py", line 696, in _slurp
    async for value in it:
  File "/Users/christopher.zerafa/Library/CloudStorage/[email protected]/My Drive/repos/ds-rg-angel/src/proj/modules/agents.py", line 101, in predict
    await agent_stopper(app)
TypeError: 'module' object is not callable
[2022-10-21 11:32:37,964] [30152] [INFO] [^----OneForOneSupervisor: (1@0x107c5c7c0)]: Restarting dead <Agent*: proj.modules.agents.predict>! Last crash reason: TypeError("'module' object is not callable") 
NoneType: None
[2022-10-21 11:32:38,969] [30152] [ERROR] [^----Agent*: proj.modules.agents.predict]: Crashed reason=TypeError("'module' object is not callable") 
Traceback (most recent call last):
  File "/Users/christopher.zerafa/Library/CloudStorage/[email protected]/My Drive/repos/ds-rg-angel/src/proj/modules/agents.py", line 36, in predict
    raise ValueError('Force fail')
ValueError: Force fail

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Caskroom/miniforge/base/envs/ds-rg-angel/lib/python3.9/site-packages/faust/agents/agent.py", line 674, in _execute_actor
    await coro
  File "/usr/local/Caskroom/miniforge/base/envs/ds-rg-angel/lib/python3.9/site-packages/faust/agents/agent.py", line 696, in _slurp
    async for value in it:
  File "/Users/christopher.zerafa/Library/CloudStorage/[email protected]/My Drive/repos/ds-rg-angel/src/proj/modules/agents.py", line 101, in predict
    await agent_stopper(app)
TypeError: 'module' object is not callable
[2022-10-21 11:32:43,972] [30152] [INFO] [^----OneForOneSupervisor: (1@0x107c5c7c0)]: Restarting dead <Agent*: proj.modules.agents.predict>! Last crash reason: TypeError("'module' object is not callable") 
NoneType: None
[2022-10-21 11:32:48,974] [30152] [ERROR] [^----Agent*: proj.modules.agents.predict]: Crashed reason=TypeError("'module' object is not callable") 
Traceback (most recent call last):
  File "/Users/christopher.zerafa/Library/CloudStorage/[email protected]/My Drive/repos/ds-rg-angel/src/proj/modules/agents.py", line 36, in predict
    raise ValueError('Force fail')
ValueError: Force fail

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Caskroom/miniforge/base/envs/ds-rg-angel/lib/python3.9/site-packages/faust/agents/agent.py", line 674, in _execute_actor
    await coro
  File "/usr/local/Caskroom/miniforge/base/envs/ds-rg-angel/lib/python3.9/site-packages/faust/agents/agent.py", line 696, in _slurp
    async for value in it:
  File "/Users/christopher.zerafa/Library/CloudStorage/[email protected]/My Drive/repos/ds-rg-angel/src/proj/modules/agents.py", line 101, in predict
    await agent_stopper(app)
TypeError: 'module' object is not callable
[2022-10-21 11:32:48,976] [30152] [INFO] [^----OneForOneSupervisor: (1@0x107c5c7c0)]: Restarting dead <Agent*: proj.modules.agents.predict>! Last crash reason: TypeError("'module' object is not callable") 
NoneType: None
[2022-10-21 11:32:53,981] [30152] [ERROR] [^----Agent*: proj.modules.agents.predict]: Crashed reason=TypeError("'module' object is not callable") 
Traceback (most recent call last):
  File "/Users/christopher.zerafa/Library/CloudStorage/[email protected]/My Drive/repos/ds-rg-angel/src/proj/modules/agents.py", line 36, in predict
    raise ValueError('Force fail')
ValueError: Force fail

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Caskroom/miniforge/base/envs/ds-rg-angel/lib/python3.9/site-packages/faust/agents/agent.py", line 674, in _execute_actor
    await coro
  File "/usr/local/Caskroom/miniforge/base/envs/ds-rg-angel/lib/python3.9/site-packages/faust/agents/agent.py", line 696, in _slurp
    async for value in it:
  File "/Users/christopher.zerafa/Library/CloudStorage/[email protected]/My Drive/repos/ds-rg-angel/src/proj/modules/agents.py", line 101, in predict
    await agent_stopper(app)
TypeError: 'module' object is not callable
[2022-10-21 11:32:53,983] [30152] [INFO] [^----OneForOneSupervisor: (1@0x107c5c7c0)]: Restarting dead <Agent*: proj.modules.agents.predict>! Last crash reason: TypeError("'module' object is not callable") 
NoneType: None
[2022-10-21 11:32:56,360] [30152] [ERROR] [^----Agent*: proj.modules.agents.predict]: Crashed reason=TypeError("'module' object is not callable") 
Traceback (most recent call last):
  File "/Users/christopher.zerafa/Library/CloudStorage/[email protected]/My Drive/repos/ds-rg-angel/src/proj/modules/agents.py", line 36, in predict
    raise ValueError('Force fail')
ValueError: Force fail

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Caskroom/miniforge/base/envs/ds-rg-angel/lib/python3.9/site-packages/faust/agents/agent.py", line 674, in _execute_actor
    await coro
  File "/usr/local/Caskroom/miniforge/base/envs/ds-rg-angel/lib/python3.9/site-packages/faust/agents/agent.py", line 696, in _slurp
    async for value in it:
  File "/Users/christopher.zerafa/Library/CloudStorage/[email protected]/My Drive/repos/ds-rg-angel/src/proj/modules/agents.py", line 101, in predict
    await agent_stopper(app)
TypeError: 'module' object is not callable

zerafachris avatar Oct 21 '22 09:10 zerafachris