Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start and restart arbitrary processes #2775

Merged
merged 19 commits into from Dec 25, 2023
Merged

Start and restart arbitrary processes #2775

merged 19 commits into from Dec 25, 2023

Conversation

ahopkins
Copy link
Member

@ahopkins ahopkins commented Jul 9, 2023

The idea is to provide a better API to allow restarting of arbitrary processes. Also, it is meant to provide a manage method to the multiplexer so that endpoints can also start arbitrary workers.

def task(n: int = 10, **kwargs):
    print("TASK STARTED", kwargs)
    for i in range(n):
        print(f"Running task - Step {i+1} of {n}")
        sleep(1)

@app.get("/restart")
async def restart_handler(request: Request):
    request.app.m.restart("Sanic-TEST-0")
    return json({"foo": request.app.m.name})


@app.get("/start")
async def start_handler(request: Request):
    request.app.m.manage("NEW", task, kwargs={"n": 7}, workers=2)
    return json({"foo": request.app.m.name})

@app.main_process_ready
def start_process(app: Sanic):
    app.manager.manage("TEST", task, kwargs={"n": 3}, restartable=True)

TODO:

  • Cleanup the API (passing messages is a bit messy)
  • Finalize the API (restartable, tracked, etc)
  • Possibly add a worker pool option?
    • Future enhancement. Not this go-around.

@ahopkins ahopkins marked this pull request as ready for review December 12, 2023 14:28
@ahopkins ahopkins requested a review from a team as a code owner December 12, 2023 14:28
Copy link

codecov bot commented Dec 12, 2023

Codecov Report

Attention: 38 lines in your changes are missing coverage. Please review.

Comparison is base (ee8e0ed) 88.391% compared to head (dbec272) 88.160%.
Report is 1 commits behind head on main.

Files Patch % Lines
sanic/worker/manager.py 67.676% 23 Missing and 9 partials ⚠️
sanic/worker/process.py 80.000% 3 Missing and 1 partial ⚠️
sanic/worker/restarter.py 93.939% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##              main     #2775       +/-   ##
=============================================
- Coverage   88.391%   88.160%   -0.231%     
=============================================
  Files           93        94        +1     
  Lines         7305      7433      +128     
  Branches      1254      1283       +29     
=============================================
+ Hits          6457      6553       +96     
- Misses         592       616       +24     
- Partials       256       264        +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ahopkins ahopkins requested a review from a team as a code owner December 13, 2023 09:06
@ahopkins ahopkins merged commit b651636 into main Dec 25, 2023
27 checks passed
@ahopkins ahopkins deleted the start-restart-manager branch December 25, 2023 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant