11import pytask
22import json
3+ import requests
34from 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 )
717def 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