Skip to content

Commit 3dfd816

Browse files
committed
Added Http communication
1 parent 03753f3 commit 3dfd816

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/pytask_vscode/execution.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import pytask
22
import json
3+
import requests
34
from multiprocessing.connection import Client
45

6+
@pytask.hookimpl(tryfirst=True)
7+
def pytask_collect_log(session: pytask.Session, reports: list[pytask.CollectionReport], tasks: list[pytask.Task]) -> None:
8+
try:
9+
if session.config['command'] == 'collect':
10+
result = [{'name' : task.short_name, 'path' : str(task.path)} for task in tasks]
11+
res = requests.post('http://localhost:6000/pytask', json={"exitcode" : session.exit_code, "tasks": result}, timeout=0.1)
12+
except Exception as e:
13+
pytask.console.print_exception()
14+
515

616
@pytask.hookimpl(tryfirst=True)
717
def pytask_execute_task_log_end(session: pytask.Session, report: pytask.ExecutionReport) -> None:
818

9-
if not session.config["dry_run"]:
10-
attrs = {"type" : "task" ,"name" : report.task.short_name, "path" : str(report.task.path), "report" : str(report.outcome)}
11-
address = ('localhost', 6000)
12-
conn = Client(address, authkey=b'secret password')
13-
conn.send(json.dumps(attrs))
14-
conn.close()
15-
16-
@pytask.hookimpl
17-
def pytask_execute_log_end(session: pytask.Session, reports: list[pytask.ExecutionReport]) -> None:
18-
if not session.config["dry_run"]:
19-
address = ('localhost', 6000)
20-
conn = Client(address, authkey=b'secret password')
21-
conn.send('close')
22-
conn.close()
19+
try:
20+
result = {'type': 'task', 'name' : report.task.short_name, 'outcome' : str(report.outcome)}
21+
res = requests.post('http://localhost:6000/pytask', json=result)
22+
except Exception as e:
23+
pytask.console.print_exception()

0 commit comments

Comments
 (0)