Skip to content

Commit

Permalink
Dont terminate child processes (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-pie authored Nov 9, 2022
1 parent dde7cb4 commit 8d21ff1
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 42 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
uses: actions/checkout@v1

- name: Start containers
run: docker-compose -f "local-dev/docker-compose.yml" up -d --build
run: docker compose -f "local-dev/docker-compose.yml" up -d --build

- name: Build dev environment
run: docker exec cicada_dev make dev

# - name: Run tests
# run: docker exec cicada_dev make pytest
- name: Run tests
run: docker exec cicada_dev make pytest

- name: Build coverage file
run: docker exec cicada_dev /bin/bash -c "source /opt/cicada/venv/bin/activate; pytest --cache-clear --cov=cicada --cov-fail-under=70" > pytest-coverage.txt
Expand All @@ -34,4 +34,4 @@ jobs:

- name: Stop containers
if: always()
run: docker-compose -f "local-dev/docker-compose.yml" down
run: docker compose -f "local-dev/docker-compose.yml" down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
- Non-running schedules can easily be moved from one node to another
- Running schedules can easily be terminated
### Execution flow diagram

![process_flow](https://github.com/transferwise/cicada/blob/master/docs/execution_flow.png?raw=True)
![Execution flow diagram](https://github.com/transferwise/cicada/blob/main/docs/execution_flow.png)

## Setup Central Database

Expand All @@ -39,8 +38,7 @@ Verified on **PostgreSQL** versions *9.6* to *12.9*
3. Execute as **cicada** user [setup/schema.sql](setup/schema.sql)

### Database ERD

![erd](https://github.com/transferwise/cicada/blob/master/docs/erd.png?raw=True)
![Database ERD](https://github.com/transferwise/cicada/blob/main/docs/erd.png)

## Setup Node

Expand Down
10 changes: 2 additions & 8 deletions cicada/commands/exec_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import datetime
import subprocess
import psutil
import os
import signal
import time
Expand Down Expand Up @@ -176,8 +175,6 @@ def main(schedule_id, dbname=None):
signal.signal(signal.SIGTERM, catch_sigterm)
signal.signal(signal.SIGQUIT, catch_sigquit)

cicada_pid = os.getpid()

error_detail = None
returncode = None

Expand Down Expand Up @@ -205,6 +202,8 @@ def main(schedule_id, dbname=None):
returncode = -15
error_detail = "Cicada abort_running"
unset_abort_running(db_cur, schedule_id)
child_process.terminate()

db_cur.close()
db_conn.close()
except Exception as error:
Expand Down Expand Up @@ -242,11 +241,6 @@ def main(schedule_id, dbname=None):
returncode = 999
error_detail = "Crazy Unknown Error"
finally:

# Terminate any zombie processes
for zombie in psutil.Process(cicada_pid).children(recursive=True):
zombie.send_signal(signal.SIGTERM)

# Repeatedly attempt to finalize schedule, even if db is unavailable
while True:
try:
Expand Down
31 changes: 14 additions & 17 deletions docs/execution_flow.graphml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:java="http://www.yworks.com/xml/yfiles-common/1.0/java" xmlns:sys="http://www.yworks.com/xml/yfiles-common/markup/primitives/2.0" xmlns:x="http://www.yworks.com/xml/yfiles-common/markup/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:y="http://www.yworks.com/xml/graphml" xmlns:yed="http://www.yworks.com/xml/yed/3" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd">
<!--Created by yEd 3.21.1-->
<!--Created by yEd 3.22-->
<key attr.name="Description" attr.type="string" for="graph" id="d0"/>
<key for="port" id="d1" yfiles.type="portgraphics"/>
<key for="port" id="d2" yfiles.type="portgeometry"/>
Expand Down Expand Up @@ -256,7 +256,7 @@
<y:Geometry height="43.05650720024016" width="207.5" x="-300.875" y="-540.6977752008406"/>
<y:Fill color="#808080" color2="#000000" transparent="false"/>
<y:BorderStyle color="#000000" raised="false" type="line" width="2.0"/>
<y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="24" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="31.9375" horizontalTextPosition="center" iconTextGap="4" modelName="custom" textColor="#FFFFFF" verticalTextPosition="bottom" visible="true" width="136.92578125" x="35.287109375" xml:space="preserve" y="5.559503600120138">executable<y:LabelModel><y:SmartNodeLabelModel distance="4.0"/></y:LabelModel><y:ModelParameter><y:SmartNodeLabelModelParameter labelRatioX="0.0" labelRatioY="0.0" nodeRatioX="0.0" nodeRatioY="0.0" offsetX="0.0" offsetY="0.0" upX="0.0" upY="-1.0"/></y:ModelParameter></y:NodeLabel>
<y:NodeLabel alignment="center" autoSizePolicy="content" fontFamily="Dialog" fontSize="24" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="31.9375" horizontalTextPosition="center" iconTextGap="4" modelName="custom" textColor="#FFFFFF" verticalTextPosition="bottom" visible="true" width="136.92578125" x="35.287109375" xml:space="preserve" y="5.559503600120024">executable<y:LabelModel><y:SmartNodeLabelModel distance="4.0"/></y:LabelModel><y:ModelParameter><y:SmartNodeLabelModelParameter labelRatioX="0.0" labelRatioY="0.0" nodeRatioX="0.0" nodeRatioY="0.0" offsetX="0.0" offsetY="0.0" upX="0.0" upY="-1.0"/></y:ModelParameter></y:NodeLabel>
<y:Shape type="roundrectangle"/>
</y:ShapeNode>
</data>
Expand Down Expand Up @@ -444,7 +444,7 @@
<y:Path sx="0.0" sy="0.0" tx="-102.80592824516623" ty="-20.10016750269297"/>
<y:LineStyle color="#000000" type="line" width="2.0"/>
<y:Arrows source="none" target="standard"/>
<y:EdgeLabel alignment="center" configuration="AutoFlippingLabel" distance="2.0" fontFamily="FreeSerif" fontSize="16" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="20.000032424926758" horizontalTextPosition="center" iconTextGap="4" modelName="side_slider" preferredPlacement="source_right" ratio="0.7000000000000001" textColor="#000000" verticalTextPosition="bottom" visible="true" width="77.69615173339844" x="100.52177102481483" xml:space="preserve" y="141.8479081851849">Syncronous<y:PreferredPlacementDescriptor angle="0.0" angleOffsetOnRightSide="0" angleReference="absolute" angleRotationOnRightSide="co" distance="-1.0" placement="source" side="right" sideReference="relative_to_edge_flow"/></y:EdgeLabel>
<y:EdgeLabel alignment="center" configuration="AutoFlippingLabel" distance="2.0" fontFamily="FreeSerif" fontSize="16" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="20.000032424926758" horizontalTextPosition="center" iconTextGap="4" modelName="side_slider" preferredPlacement="source_right" ratio="0.7000000000000001" textColor="#000000" verticalTextPosition="bottom" visible="true" width="77.69615173339844" x="108.88835517742723" xml:space="preserve" y="148.43317078485282">Syncronous<y:PreferredPlacementDescriptor angle="0.0" angleOffsetOnRightSide="0" angleReference="absolute" angleRotationOnRightSide="co" distance="-1.0" placement="source" side="right" sideReference="relative_to_edge_flow"/></y:EdgeLabel>
<y:BendStyle smoothed="true"/>
</y:PolyLineEdge>
</data>
Expand All @@ -464,7 +464,7 @@
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="18.96981445312531" sy="-151.11301440048044" tx="0.0" ty="-5.0"/>
<y:LineStyle color="#000000" type="line" width="2.0"/>
<y:LineStyle color="#000000" type="dashed" width="2.0"/>
<y:Arrows source="none" target="standard"/>
<y:BendStyle smoothed="false"/>
</y:PolyLineEdge>
Expand All @@ -474,7 +474,7 @@
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="6.832656250000355" sy="-73.05650720024016" tx="0.0" ty="0.0"/>
<y:LineStyle color="#000000" type="line" width="2.0"/>
<y:LineStyle color="#000000" type="dashed" width="2.0"/>
<y:Arrows source="none" target="standard"/>
<y:BendStyle smoothed="false"/>
</y:PolyLineEdge>
Expand All @@ -484,7 +484,7 @@
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="-5.286000000000058" sy="-5.6843418860808015E-14" tx="-103.72467041015625" ty="0.0"/>
<y:LineStyle color="#000000" type="line" width="2.0"/>
<y:LineStyle color="#000000" type="dashed" width="2.0"/>
<y:Arrows source="none" target="standard"/>
<y:BendStyle smoothed="false"/>
</y:PolyLineEdge>
Expand All @@ -494,7 +494,7 @@
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="6.857656250000332" sy="74.60028478667891" tx="-19.336093749999918" ty="1.5437775864386936"/>
<y:LineStyle color="#000000" type="line" width="2.0"/>
<y:LineStyle color="#000000" type="dashed" width="2.0"/>
<y:Arrows source="none" target="standard"/>
<y:BendStyle smoothed="false"/>
</y:PolyLineEdge>
Expand All @@ -504,7 +504,7 @@
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="18.995156250000377" sy="148.0377847866788" tx="-17.773593749999918" ty="1.9247703861984178"/>
<y:LineStyle color="#000000" type="line" width="2.0"/>
<y:LineStyle color="#000000" type="dashed" width="2.0"/>
<y:Arrows source="none" target="standard"/>
<y:BendStyle smoothed="false"/>
</y:PolyLineEdge>
Expand All @@ -513,9 +513,8 @@
<edge id="e18" source="n2" target="n5">
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="-97.83411394528287" sy="21.515970938237416" tx="-97.83411394528287" ty="-21.497823677645556">
<y:Point x="-576.9435062408447" y="-71.86043677469777"/>
<y:Point x="-576.9435062408447" y="-37.93073859082119"/>
<y:Path sx="-103.62352965436503" sy="-20.662058000613612" tx="-102.56572817406561" ty="-20.39090971749117">
<y:Point x="-577.8301730864362" y="-75.54458494623654"/>
</y:Path>
<y:LineStyle color="#000000" type="line" width="2.0"/>
<y:Arrows source="none" target="standard"/>
Expand All @@ -526,9 +525,9 @@
<edge id="e19" source="n5" target="n7">
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="-100.9435220000014" sy="21.34981573381205" tx="-99.56960800000184" ty="-20.362692799760225">
<y:Path sx="-101.52825346189468" sy="-21.11326805595661" tx="-102.59482957410728" ty="-20.304366967417074">
<y:Point x="-556.5640571182795" y="-37.929297204301236"/>
<y:Point x="-576.9435062408447" y="4.916900820636414"/>
<y:Point x="-578.2620124816895" y="40.14788508682369"/>
</y:Path>
<y:LineStyle color="#000000" type="line" width="2.0"/>
<y:Arrows source="none" target="standard"/>
Expand All @@ -539,9 +538,8 @@
<edge id="e20" source="n7" target="n9">
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="-102.44884190435118" sy="20.495187673467427" tx="-102.8286875260294" ty="-20.060059843371732">
<y:Path sx="-103.19169025911162" sy="-20.17637482215426" tx="-102.8286875260294" ty="-20.060059843371732">
<y:Point x="-578.2620124816895" y="81.00576556005134"/>
<y:Point x="-578.2620124816895" y="117.39401084297174"/>
</y:Path>
<y:LineStyle color="#000000" type="line" width="2.0"/>
<y:Arrows source="none" target="standard"/>
Expand All @@ -552,9 +550,8 @@
<edge id="e21" source="n9" target="n11">
<data key="d10">
<y:PolyLineEdge>
<y:Path sx="-101.26786405758969" sy="21.25630759226982" tx="-102.14914231556702" ty="-20.685970972203734">
<y:Path sx="-102.24696246368183" sy="-20.647516604895458" tx="-102.84447546342324" ty="-20.030313395772026">
<y:Point x="-578.2620124816895" y="158.7103782786133"/>
<y:Point x="-578.2620124816895" y="193.7115925138993"/>
</y:Path>
<y:LineStyle color="#000000" type="line" width="2.0"/>
<y:Arrows source="none" target="standard"/>
Expand Down
Binary file modified docs/execution_flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions local-dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Go to the main folder of the repository (the parent of this one) and To create l

```sh
$ cd local-dev/
$ docker-compose up --build
$ docker compose up --build
```

Wait until `Cicada Dev environment is ready in Docker container(s).` message. At the first run this can
Expand Down Expand Up @@ -51,5 +51,5 @@ To refresh the containers with new local code changes stop the running instances

```sh
$ ./refresh-local-dev.sh
$ docker-compose up
$ docker compose up
```
3 changes: 3 additions & 0 deletions local-dev/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ fi
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
source /opt/cicada/venv/bin/activate
EOL


Expand Down
2 changes: 1 addition & 1 deletion local-dev/refresh-local-dev.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/bash

docker-compose down
docker compose down
docker system prune --volumes --force
sudo rm ../venv/ -Rf

11 changes: 5 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="cicada",
version="0.3.4",
version="0.4.0",
description="Lightweight, agent-based, distributed scheduler",
long_description=long_description,
long_description_content_type="text/markdown",
Expand All @@ -18,18 +18,17 @@
"Programming Language :: Python :: 3 :: Only",
],
install_requires=[
"psycopg2-binary==2.9.3",
"psycopg2-binary==2.9.5",
"pyyaml==6.0",
"croniter==1.3.7",
"tabulate==0.8.10",
"tabulate==0.9.0",
"slack-sdk==3.19.1",
"backoff==2.1.2",
"psutil==5.9.2",
"backoff==2.2.1",
],
extras_require={
"dev": [
"pytest==7.1.3",
"pytest-cov==3.0.0",
"pytest-cov==4.0.0",
"black==22.10.0",
"flake8==5.0.4",
"freezegun==1.2.2",
Expand Down

0 comments on commit 8d21ff1

Please sign in to comment.