Spaces:
Sleeping
Sleeping
hahunavth
commited on
Commit
•
2b0538d
1
Parent(s):
edf61c6
update v1.0.1
Browse files- .gitignore +2 -1
- __pycache__/google_sheet.cpython-310.pyc +0 -0
- __pycache__/kaggle_service.cpython-310.pyc +0 -0
- __pycache__/logger.cpython-310.pyc +0 -0
- google_sheet.py +3 -2
- kaggle_service.py +92 -13
- logger.py +2 -3
- main.py +66 -6
- version.py +1 -0
.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
tmp
|
|
|
|
1 |
+
tmp
|
2 |
+
__pycache__
|
__pycache__/google_sheet.cpython-310.pyc
DELETED
Binary file (3.07 kB)
|
|
__pycache__/kaggle_service.cpython-310.pyc
DELETED
Binary file (15.4 kB)
|
|
__pycache__/logger.cpython-310.pyc
DELETED
Binary file (2.17 kB)
|
|
google_sheet.py
CHANGED
@@ -51,10 +51,11 @@ def create_repositories():
|
|
51 |
|
52 |
config_repository = SheetCRUDRepository(sheet.get_worksheet(0))
|
53 |
log_repository = SheetCRUDRepository(sheet.get_worksheet(1))
|
54 |
-
|
|
|
55 |
|
56 |
|
57 |
-
conf_repo, log_repo = create_repositories()
|
58 |
|
59 |
|
60 |
if __name__ == "__main__":
|
|
|
51 |
|
52 |
config_repository = SheetCRUDRepository(sheet.get_worksheet(0))
|
53 |
log_repository = SheetCRUDRepository(sheet.get_worksheet(1))
|
54 |
+
secret_repository = SheetCRUDRepository(sheet.get_worksheet(2))
|
55 |
+
return config_repository, log_repository, secret_repository
|
56 |
|
57 |
|
58 |
+
conf_repo, log_repo, secret_repo = create_repositories()
|
59 |
|
60 |
|
61 |
if __name__ == "__main__":
|
kaggle_service.py
CHANGED
@@ -44,6 +44,83 @@ class KaggleApiWrapper(KaggleApi):
|
|
44 |
# todo: fix bug when delete api
|
45 |
pass
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
class ValidateException(Exception):
|
49 |
def __init__(self, message: str):
|
@@ -309,14 +386,16 @@ class NbJob:
|
|
309 |
sheet_logger.log(username=api.username, nb=self.nb_slug, log="Try but no effect. Seem account to be out of quota")
|
310 |
return False
|
311 |
if status3 in self.not_rerun_stt:
|
312 |
-
sheet_logger.log(username=api.username, nb=self.nb_slug, log=f"Notebook status is {status3} is in ignore status list {self.not_rerun_stt}, do nothing!")
|
|
|
|
|
313 |
return True
|
314 |
if status3 not in ["queued", "running"]:
|
315 |
# return False # todo: check when user is out of quota
|
316 |
print(f"Error: status is {status3}")
|
|
|
317 |
raise Exception("Setup exception")
|
318 |
-
|
319 |
-
log=f"Schedule notebook successfully. Current status is '{status3}'")
|
320 |
return True
|
321 |
|
322 |
sheet_logger.log(username=api.username, nb=self.nb_slug, log=f"Notebook status is '{status1}' is not in {self.rerun_stt}, do nothing!")
|
@@ -428,16 +507,16 @@ class KernelRerunService:
|
|
428 |
print(f"Job: {job.nb_slug} {success}")
|
429 |
|
430 |
|
431 |
-
if __name__ == "__main__":
|
432 |
-
service = KernelRerunService()
|
433 |
-
files = os.listdir("./config")
|
434 |
-
for file in files:
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
service.run_all()
|
441 |
|
442 |
# try:
|
443 |
# acc_secret_dict = {
|
|
|
44 |
# todo: fix bug when delete api
|
45 |
pass
|
46 |
|
47 |
+
# def get_accelerator_quota_with_http_info(self): # noqa: E501
|
48 |
+
# """
|
49 |
+
#
|
50 |
+
# This method makes a synchronous HTTP request by default. To make an
|
51 |
+
# asynchronous HTTP request, please pass async_req=True
|
52 |
+
# >>> thread = api.competitions_list_with_http_info(async_req=True)
|
53 |
+
# >>> result = thread.get()
|
54 |
+
#
|
55 |
+
# :param async_req bool
|
56 |
+
# :param str group: Filter competitions by a particular group
|
57 |
+
# :param str category: Filter competitions by a particular category
|
58 |
+
# :param str sort_by: Sort the results
|
59 |
+
# :param int page: Page number
|
60 |
+
# :param str search: Search terms
|
61 |
+
# :return: Result
|
62 |
+
# If the method is called asynchronously,
|
63 |
+
# returns the request thread.
|
64 |
+
# """
|
65 |
+
#
|
66 |
+
# all_params = [] # noqa: E501
|
67 |
+
# all_params.append('async_req')
|
68 |
+
# all_params.append('_return_http_data_only')
|
69 |
+
# all_params.append('_preload_content')
|
70 |
+
# all_params.append('_request_timeout')
|
71 |
+
#
|
72 |
+
# params = locals()
|
73 |
+
#
|
74 |
+
# collection_formats = {}
|
75 |
+
#
|
76 |
+
# path_params = {}
|
77 |
+
#
|
78 |
+
# query_params = []
|
79 |
+
# # if 'group' in params:
|
80 |
+
# # query_params.append(('group', params['group'])) # noqa: E501
|
81 |
+
# # if 'category' in params:
|
82 |
+
# # query_params.append(('category', params['category'])) # noqa: E501
|
83 |
+
# # if 'sort_by' in params:
|
84 |
+
# # query_params.append(('sortBy', params['sort_by'])) # noqa: E501
|
85 |
+
# # if 'page' in params:
|
86 |
+
# # query_params.append(('page', params['page'])) # noqa: E501
|
87 |
+
# # if 'search' in params:
|
88 |
+
# # query_params.append(('search', params['search'])) # noqa: E501
|
89 |
+
#
|
90 |
+
# header_params = {}
|
91 |
+
#
|
92 |
+
# form_params = []
|
93 |
+
# local_var_files = {}
|
94 |
+
#
|
95 |
+
# body_params = None
|
96 |
+
# # HTTP header `Accept`
|
97 |
+
# header_params['Accept'] = self.api_client.select_header_accept(
|
98 |
+
# ['application/json']) # noqa: E501
|
99 |
+
#
|
100 |
+
# # Authentication setting
|
101 |
+
# auth_settings = ['basicAuth'] # noqa: E501
|
102 |
+
#
|
103 |
+
# return self.api_client.call_api(
|
104 |
+
# 'i/kernels.KernelsService/GetAcceleratorQuotaStatistics', 'GET',
|
105 |
+
# # '/competitions/list', 'GET',
|
106 |
+
# path_params,
|
107 |
+
# query_params,
|
108 |
+
# header_params,
|
109 |
+
# body=body_params,
|
110 |
+
# post_params=form_params,
|
111 |
+
# files=local_var_files,
|
112 |
+
# response_type='Result', # noqa: E501
|
113 |
+
# auth_settings=auth_settings,
|
114 |
+
# async_req=params.get('async_req'),
|
115 |
+
# _return_http_data_only=params.get('_return_http_data_only'),
|
116 |
+
# _preload_content=params.get('_preload_content', True),
|
117 |
+
# _request_timeout=params.get('_request_timeout'),
|
118 |
+
# collection_formats=collection_formats)
|
119 |
+
#
|
120 |
+
# if __name__ == "__main__":
|
121 |
+
# api = KaggleApiWrapper('ha.vt194547@sis.hust.edu.vn', "c54e96568075fcc277bd10ba0e0a52b9")
|
122 |
+
# api.authenticate()
|
123 |
+
# print(api.get_accelerator_quota_with_http_info())
|
124 |
|
125 |
class ValidateException(Exception):
|
126 |
def __init__(self, message: str):
|
|
|
386 |
sheet_logger.log(username=api.username, nb=self.nb_slug, log="Try but no effect. Seem account to be out of quota")
|
387 |
return False
|
388 |
if status3 in self.not_rerun_stt:
|
389 |
+
# sheet_logger.log(username=api.username, nb=self.nb_slug, log=f"Notebook status is {status3} is in ignore status list {self.not_rerun_stt}, do nothing!")
|
390 |
+
sheet_logger.log(username=api.username, nb=self.nb_slug,
|
391 |
+
log=f"Schedule notebook successfully. Current status is '{status3}'")
|
392 |
return True
|
393 |
if status3 not in ["queued", "running"]:
|
394 |
# return False # todo: check when user is out of quota
|
395 |
print(f"Error: status is {status3}")
|
396 |
+
|
397 |
raise Exception("Setup exception")
|
398 |
+
|
|
|
399 |
return True
|
400 |
|
401 |
sheet_logger.log(username=api.username, nb=self.nb_slug, log=f"Notebook status is '{status1}' is not in {self.rerun_stt}, do nothing!")
|
|
|
507 |
print(f"Job: {job.nb_slug} {success}")
|
508 |
|
509 |
|
510 |
+
# if __name__ == "__main__":
|
511 |
+
# service = KernelRerunService()
|
512 |
+
# files = os.listdir("./config")
|
513 |
+
# for file in files:
|
514 |
+
# if '.example' not in file:
|
515 |
+
# with open(os.path.join("./config", file), "r") as f:
|
516 |
+
# obj = json.loads(f.read())
|
517 |
+
# print(obj)
|
518 |
+
# service.add_job(NbJob.from_dict(obj))
|
519 |
+
# service.run_all()
|
520 |
|
521 |
# try:
|
522 |
# acc_secret_dict = {
|
logger.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
import platform,socket,re,uuid,json,psutil,logging
|
2 |
from datetime import datetime as dt
|
3 |
from google_sheet import log_repo, conf_repo, SheetCRUDRepository
|
4 |
-
|
5 |
-
version="v1.0.0"
|
6 |
|
7 |
|
8 |
def get_sys_info():
|
@@ -34,7 +33,7 @@ class SheetLogger:
|
|
34 |
"kaggle_username": username,
|
35 |
"log": log,
|
36 |
"device": str(get_sys_info()),
|
37 |
-
"version":
|
38 |
})
|
39 |
|
40 |
def update_job_status(self, row, validate_status: str = None, notebook_status: str = None):
|
|
|
1 |
import platform,socket,re,uuid,json,psutil,logging
|
2 |
from datetime import datetime as dt
|
3 |
from google_sheet import log_repo, conf_repo, SheetCRUDRepository
|
4 |
+
from version import VERSION
|
|
|
5 |
|
6 |
|
7 |
def get_sys_info():
|
|
|
33 |
"kaggle_username": username,
|
34 |
"log": log,
|
35 |
"device": str(get_sys_info()),
|
36 |
+
"version": VERSION
|
37 |
})
|
38 |
|
39 |
def update_job_status(self, row, validate_status: str = None, notebook_status: str = None):
|
main.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from google_sheet import conf_repo
|
2 |
import json
|
3 |
|
4 |
from kaggle_service import KernelRerunService, NbJob
|
@@ -6,23 +6,81 @@ from logger import sheet_logger
|
|
6 |
|
7 |
|
8 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
configs = []
|
10 |
ids = []
|
11 |
try:
|
12 |
-
for i in range(2,
|
13 |
rs = conf_repo.read(i)
|
14 |
if not rs:
|
15 |
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
cfg = json.loads(rs['config'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
configs.append(cfg)
|
19 |
ids.append(i)
|
20 |
print(cfg)
|
21 |
-
except
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
25 |
|
|
|
26 |
service = KernelRerunService()
|
27 |
for config, idx in zip(configs, ids):
|
28 |
try:
|
@@ -30,6 +88,7 @@ if __name__ == "__main__":
|
|
30 |
except Exception as e:
|
31 |
sheet_logger.update_job_status(idx, validate_status=str(e))
|
32 |
|
|
|
33 |
try:
|
34 |
service.validate_all()
|
35 |
# service.status_all()
|
@@ -37,3 +96,4 @@ if __name__ == "__main__":
|
|
37 |
except Exception as e:
|
38 |
sheet_logger.log(log=str(e))
|
39 |
|
|
|
|
1 |
+
from google_sheet import conf_repo, secret_repo
|
2 |
import json
|
3 |
|
4 |
from kaggle_service import KernelRerunService, NbJob
|
|
|
6 |
|
7 |
|
8 |
if __name__ == "__main__":
|
9 |
+
sheet_logger.log("========= start ==========")
|
10 |
+
|
11 |
+
# load all account and secret into a dict
|
12 |
+
secret_dict = {}
|
13 |
+
try:
|
14 |
+
for i in range(2, 50): # note: read row 2 - 50
|
15 |
+
rs = secret_repo.read(i)
|
16 |
+
if not rs:
|
17 |
+
break
|
18 |
+
assert 'username' in rs
|
19 |
+
assert 'secret' in rs
|
20 |
+
|
21 |
+
username = rs['username'].rstrip()
|
22 |
+
secret = rs['secret'].rstrip()
|
23 |
+
|
24 |
+
secret_dict[username] = secret
|
25 |
+
except Exception as e:
|
26 |
+
sheet_logger.log(log="Get secret table failed!!" + str(e))
|
27 |
+
|
28 |
+
# load config from gg sheet file
|
29 |
configs = []
|
30 |
ids = []
|
31 |
try:
|
32 |
+
for i in range(2, 50): # note: read row 2 - 50
|
33 |
rs = conf_repo.read(i)
|
34 |
if not rs:
|
35 |
break
|
36 |
+
if not rs['config']:
|
37 |
+
reset_keys = []
|
38 |
+
for key in rs:
|
39 |
+
if rs[key]:
|
40 |
+
reset_keys.append(key)
|
41 |
+
if len(reset_keys) > 0:
|
42 |
+
conf_repo.update(row_index=i, data={k: '' for k in reset_keys})
|
43 |
+
break
|
44 |
+
print(i, rs)
|
45 |
try:
|
46 |
+
# validation
|
47 |
+
# assert 'config' in rs, 'require config column'
|
48 |
+
assert 'usernames' in rs, 'require usernames column'
|
49 |
+
assert 'enable' in rs, 'require enable column'
|
50 |
+
|
51 |
+
assert rs['enable'].rstrip() in ['enable', 'disable'], rs['enable']
|
52 |
+
assert 'slug' in rs['config'], 'require config.slug'
|
53 |
+
|
54 |
cfg = json.loads(rs['config'])
|
55 |
+
usernames = set(rs['usernames']
|
56 |
+
.rstrip().replace('\n', ' ').replace(',', ' ').replace(';', ' ').replace('|', ' ')
|
57 |
+
.split(' '))
|
58 |
+
usernames = [u for u in usernames if u]
|
59 |
+
is_enabled = rs['enable'].rstrip() == 'enable'
|
60 |
+
if not is_enabled:
|
61 |
+
sheet_logger.log(log="Disabled, skip!", nb=cfg['slug'])
|
62 |
+
print("skip ", cfg['slug'])
|
63 |
+
continue
|
64 |
+
|
65 |
+
assert len(usernames) > 0, 'len usernames == 0'
|
66 |
+
|
67 |
+
# process config
|
68 |
+
accounts = {u: secret_dict[u] for u in secret_dict if u in usernames}
|
69 |
+
assert not set(usernames).difference(set(accounts.keys())), set(usernames).difference(set(accounts.keys()))
|
70 |
+
cfg = {**cfg, "accounts": accounts}
|
71 |
+
|
72 |
+
# save
|
73 |
configs.append(cfg)
|
74 |
ids.append(i)
|
75 |
print(cfg)
|
76 |
+
except AssertionError:
|
77 |
+
import traceback
|
78 |
+
sheet_logger.update_job_status(i, validate_status=str(traceback.format_exc()))
|
79 |
+
except Exception:
|
80 |
+
import traceback
|
81 |
+
sheet_logger.log(log="Get config failed!!" + str(traceback.format_exc()))
|
82 |
|
83 |
+
# add config to service
|
84 |
service = KernelRerunService()
|
85 |
for config, idx in zip(configs, ids):
|
86 |
try:
|
|
|
88 |
except Exception as e:
|
89 |
sheet_logger.update_job_status(idx, validate_status=str(e))
|
90 |
|
91 |
+
# run service
|
92 |
try:
|
93 |
service.validate_all()
|
94 |
# service.status_all()
|
|
|
96 |
except Exception as e:
|
97 |
sheet_logger.log(log=str(e))
|
98 |
|
99 |
+
sheet_logger.log("========= end ==========")
|
version.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
VERSION="v1.0.1"
|