schd 0.0.16__tar.gz → 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {schd-0.0.16 → schd-0.1.1}/PKG-INFO +11 -8
- schd-0.1.1/schd/__init__.py +1 -0
- {schd-0.0.16 → schd-0.1.1}/schd/cmds/base.py +1 -1
- {schd-0.0.16 → schd-0.1.1}/schd/cmds/daemon.py +3 -5
- schd-0.1.1/schd/cmds/jobs.py +19 -0
- schd-0.1.1/schd/cmds/run.py +27 -0
- {schd-0.0.16 → schd-0.1.1}/schd/cmds/schd.py +9 -3
- schd-0.1.1/schd/cmds/scsendmail.py +87 -0
- {schd-0.0.16 → schd-0.1.1}/schd/config.py +57 -7
- schd-0.1.1/schd/email.py +71 -0
- {schd-0.0.16 → schd-0.1.1}/schd/scheduler.py +18 -8
- {schd-0.0.16 → schd-0.1.1}/schd.egg-info/PKG-INFO +11 -8
- {schd-0.0.16 → schd-0.1.1}/schd.egg-info/SOURCES.txt +4 -1
- {schd-0.0.16 → schd-0.1.1}/schd.egg-info/entry_points.txt +1 -0
- {schd-0.0.16 → schd-0.1.1}/setup.cfg +7 -7
- {schd-0.0.16 → schd-0.1.1}/setup.py +2 -1
- schd-0.1.1/tests/test_config.py +29 -0
- schd-0.1.1/tests/test_email.py +68 -0
- {schd-0.0.16 → schd-0.1.1}/tests/test_scheduler.py +4 -3
- schd-0.0.16/LICENSE +0 -201
- schd-0.0.16/schd/__init__.py +0 -1
- schd-0.0.16/schd/cmds/jobs.py +0 -16
- schd-0.0.16/schd/cmds/run.py +0 -26
- {schd-0.0.16 → schd-0.1.1}/README.md +0 -0
- {schd-0.0.16 → schd-0.1.1}/schd/cmds/__init__.py +0 -0
- {schd-0.0.16 → schd-0.1.1}/schd/job.py +0 -0
- {schd-0.0.16 → schd-0.1.1}/schd/schedulers/__init__.py +0 -0
- {schd-0.0.16 → schd-0.1.1}/schd/schedulers/remote.py +0 -0
- {schd-0.0.16 → schd-0.1.1}/schd/util.py +0 -0
- {schd-0.0.16 → schd-0.1.1}/schd.egg-info/dependency_links.txt +0 -0
- {schd-0.0.16 → schd-0.1.1}/schd.egg-info/requires.txt +0 -0
- {schd-0.0.16 → schd-0.1.1}/schd.egg-info/top_level.txt +0 -0
- {schd-0.0.16 → schd-0.1.1}/tests/test_util.py +0 -0
@@ -1,8 +1,11 @@
|
|
1
|
-
Metadata-Version: 2.
|
2
|
-
Name: schd
|
3
|
-
Version: 0.
|
4
|
-
Home-page: https://github.com/kevenli/schd
|
5
|
-
License: ApacheV2
|
6
|
-
Requires-Dist: apscheduler<4.0
|
7
|
-
Requires-Dist: pyaml
|
8
|
-
Requires-Dist: aiohttp
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: schd
|
3
|
+
Version: 0.1.1
|
4
|
+
Home-page: https://github.com/kevenli/schd
|
5
|
+
License: ApacheV2
|
6
|
+
Requires-Dist: apscheduler<4.0
|
7
|
+
Requires-Dist: pyaml
|
8
|
+
Requires-Dist: aiohttp
|
9
|
+
Dynamic: home-page
|
10
|
+
Dynamic: license
|
11
|
+
Dynamic: requires-dist
|
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = '0.1.1'
|
@@ -8,12 +8,10 @@ from schd import __version__ as schd_version
|
|
8
8
|
|
9
9
|
class DaemonCommand(CommandBase):
|
10
10
|
def add_arguments(self, parser):
|
11
|
-
parser.add_argument('--config', '-c')
|
12
11
|
parser.add_argument('--logfile')
|
13
12
|
|
14
|
-
def run(self, args):
|
15
|
-
|
16
|
-
print(f'starting schd, {schd_version}, config_file={config_file}')
|
13
|
+
def run(self, args, config):
|
14
|
+
print(f'starting schd, {schd_version}')
|
17
15
|
|
18
16
|
if args.logfile:
|
19
17
|
log_stream = open(args.logfile, 'a', encoding='utf8')
|
@@ -23,4 +21,4 @@ class DaemonCommand(CommandBase):
|
|
23
21
|
log_stream = sys.stdout
|
24
22
|
|
25
23
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(name)s %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', stream=log_stream)
|
26
|
-
asyncio.run(run_daemon(
|
24
|
+
asyncio.run(run_daemon(config))
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"""
|
2
|
+
list jobs
|
3
|
+
"""
|
4
|
+
import sys
|
5
|
+
from .base import CommandBase
|
6
|
+
|
7
|
+
|
8
|
+
class JobsCommand(CommandBase):
|
9
|
+
def add_arguments(self, parser):
|
10
|
+
# parser.add_argument('--config', '-c', default=None, help='config file')
|
11
|
+
pass
|
12
|
+
|
13
|
+
def run(self, args, config=None):
|
14
|
+
if config is None:
|
15
|
+
print("No configuration provided.")
|
16
|
+
sys.exit(1)
|
17
|
+
|
18
|
+
for job_name, _ in config.jobs.items():
|
19
|
+
print(job_name)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import asyncio
|
2
|
+
import logging
|
3
|
+
import sys
|
4
|
+
from schd.cmds.base import CommandBase
|
5
|
+
from schd.scheduler import LocalScheduler, build_job
|
6
|
+
|
7
|
+
|
8
|
+
async def run_job(config, job_name):
|
9
|
+
scheduler = LocalScheduler(config)
|
10
|
+
job_config = config.jobs[job_name]
|
11
|
+
job = build_job(job_name, job_config.cls, job_config)
|
12
|
+
await scheduler.add_job(job, job_name, job_config)
|
13
|
+
scheduler.execute_job(job_name)
|
14
|
+
|
15
|
+
|
16
|
+
class RunCommand(CommandBase):
|
17
|
+
def add_arguments(self, parser):
|
18
|
+
parser.add_argument('job')
|
19
|
+
|
20
|
+
def run(self, args, config):
|
21
|
+
if config is None:
|
22
|
+
print("No configuration provided.")
|
23
|
+
sys.exit(1)
|
24
|
+
|
25
|
+
logging.basicConfig(format='%(asctime)s %(name)s - %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', level=logging.INFO)
|
26
|
+
job_name = args.job
|
27
|
+
asyncio.run(run_job(config, job_name))
|
@@ -1,10 +1,11 @@
|
|
1
1
|
import argparse
|
2
2
|
import sys
|
3
3
|
from schd.cmds.jobs import JobsCommand
|
4
|
-
from schd.
|
4
|
+
from schd.config import ConfigFileNotFound, read_config
|
5
|
+
from schd import __version__ as schd_version
|
5
6
|
from .daemon import DaemonCommand
|
6
7
|
from .run import RunCommand
|
7
|
-
|
8
|
+
|
8
9
|
|
9
10
|
commands = {
|
10
11
|
'daemon': DaemonCommand(),
|
@@ -16,6 +17,7 @@ def main():
|
|
16
17
|
sys.path.append('.')
|
17
18
|
parser = argparse.ArgumentParser('schd')
|
18
19
|
parser.add_argument('--version', action='store_true', default=False)
|
20
|
+
parser.add_argument('--config')
|
19
21
|
sub_command_parsers = parser.add_subparsers(dest='cmd')
|
20
22
|
|
21
23
|
for cmd, cmd_obj in commands.items():
|
@@ -23,6 +25,10 @@ def main():
|
|
23
25
|
cmd_obj.add_arguments(sub_command_parser)
|
24
26
|
|
25
27
|
args = parser.parse_args()
|
28
|
+
try:
|
29
|
+
config = read_config(args.config)
|
30
|
+
except ConfigFileNotFound:
|
31
|
+
config = None
|
26
32
|
|
27
33
|
if args.version:
|
28
34
|
print('schd version ', schd_version)
|
@@ -32,7 +38,7 @@ def main():
|
|
32
38
|
parser.print_help()
|
33
39
|
return
|
34
40
|
|
35
|
-
commands[args.cmd].run(args)
|
41
|
+
commands[args.cmd].run(args, config=config)
|
36
42
|
|
37
43
|
|
38
44
|
if __name__ == '__main__':
|
@@ -0,0 +1,87 @@
|
|
1
|
+
"""
|
2
|
+
scsendmail - Send email via command line using EmailService
|
3
|
+
|
4
|
+
Usage:
|
5
|
+
scsendmail --to someone@example.com --title "Report" --content "Text body"
|
6
|
+
scsendmail --to a@example.com --content-html-file ./body.html -a report.pdf
|
7
|
+
"""
|
8
|
+
|
9
|
+
import argparse
|
10
|
+
import logging
|
11
|
+
from pathlib import Path
|
12
|
+
from typing import List, Optional
|
13
|
+
import sys
|
14
|
+
|
15
|
+
from schd.config import read_config, ConfigFileNotFound, EmailConfig
|
16
|
+
from schd.email import EmailService
|
17
|
+
|
18
|
+
|
19
|
+
def parse_recipients(values: Optional[List[str]]) -> List[str]:
|
20
|
+
if not values:
|
21
|
+
return []
|
22
|
+
emails = []
|
23
|
+
for val in values:
|
24
|
+
emails.extend(email.strip() for email in val.split(',') if email.strip())
|
25
|
+
return emails
|
26
|
+
|
27
|
+
|
28
|
+
def main():
|
29
|
+
parser = argparse.ArgumentParser(description='scsendmail command')
|
30
|
+
parser.add_argument('--title', default='report', help='Email subject')
|
31
|
+
parser.add_argument('--content', default='no content', help='Plain text content')
|
32
|
+
parser.add_argument('--content-html-file', help='Path to HTML file for HTML content')
|
33
|
+
parser.add_argument('--to', dest='recipients', action='append', help='To recipients (comma-separated or multiple flags)')
|
34
|
+
parser.add_argument('--cc', action='append', help='CC recipients (comma-separated or multiple flags)')
|
35
|
+
parser.add_argument('--bcc', action='append', help='BCC recipients (comma-separated or multiple flags)')
|
36
|
+
parser.add_argument('--add-attach', '-a', action='append', dest='attachments', help='Attachment file paths')
|
37
|
+
parser.add_argument('--debug', action='store_true', default=False, help='Print instead of sending')
|
38
|
+
parser.add_argument('--config')
|
39
|
+
parser.add_argument('--loglevel', default='INFO', help='Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)')
|
40
|
+
|
41
|
+
args = parser.parse_args()
|
42
|
+
|
43
|
+
logging.basicConfig(level=args.loglevel.upper(),
|
44
|
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
45
|
+
|
46
|
+
# Load HTML content if provided
|
47
|
+
html_content = None
|
48
|
+
if args.content_html_file:
|
49
|
+
try:
|
50
|
+
html_content = Path(args.content_html_file).read_text(encoding='utf-8')
|
51
|
+
except Exception as e:
|
52
|
+
print(f"Failed to read HTML content file: {e}", file=sys.stderr)
|
53
|
+
sys.exit(1)
|
54
|
+
|
55
|
+
# Load config from environment or config file
|
56
|
+
schd_config = read_config(args.config)
|
57
|
+
logging.debug(schd_config.email)
|
58
|
+
service = EmailService.from_config(schd_config.email)
|
59
|
+
|
60
|
+
to_emails = parse_recipients(args.recipients)
|
61
|
+
cc_emails = parse_recipients(args.cc)
|
62
|
+
bcc_emails = parse_recipients(args.bcc)
|
63
|
+
attachments = args.attachments or []
|
64
|
+
|
65
|
+
if args.debug:
|
66
|
+
print("DEBUG MODE: Email will not be sent")
|
67
|
+
print(f"Subject: {args.title}")
|
68
|
+
print(f"To: {to_emails}")
|
69
|
+
print(f"CC: {cc_emails}")
|
70
|
+
print(f"BCC: {bcc_emails}")
|
71
|
+
print(f"Attachments: {attachments}")
|
72
|
+
print(f"Content: {args.content}")
|
73
|
+
print(f"HTML Content File: {args.content_html_file}")
|
74
|
+
else:
|
75
|
+
service.send_mail(
|
76
|
+
title=args.title,
|
77
|
+
content=args.content,
|
78
|
+
content_html=html_content,
|
79
|
+
to_emails=to_emails,
|
80
|
+
cc_emails=cc_emails,
|
81
|
+
bcc_emails=bcc_emails,
|
82
|
+
attachments=attachments
|
83
|
+
)
|
84
|
+
|
85
|
+
|
86
|
+
if __name__ == '__main__':
|
87
|
+
main()
|
@@ -28,15 +28,20 @@ class ConfigValue:
|
|
28
28
|
type_hints = get_type_hints(cls)
|
29
29
|
init_data:Dict[str,Any] = {}
|
30
30
|
if not is_dataclass(cls):
|
31
|
-
raise TypeError('class
|
31
|
+
raise TypeError(f'class {cls} is not dataclass')
|
32
32
|
|
33
33
|
for f in fields(cls):
|
34
34
|
field_name = f.name
|
35
35
|
json_key = f.metadata.get("json", f.name)
|
36
|
+
envvar_key = f.metadata.get('env_var')
|
36
37
|
field_type = type_hints[field_name]
|
37
38
|
origin = get_origin(field_type)
|
38
39
|
args = get_args(field_type)
|
39
40
|
|
41
|
+
if envvar_key and envvar_key in os.environ:
|
42
|
+
init_data[field_name] = _cast_type(os.environ[envvar_key], field_type)
|
43
|
+
continue
|
44
|
+
|
40
45
|
if json_key in data:
|
41
46
|
value = data[json_key]
|
42
47
|
# Handle nested ConfigValue objects
|
@@ -63,6 +68,44 @@ class ConfigValue:
|
|
63
68
|
init_data[field_name] = value
|
64
69
|
return cls(**init_data)
|
65
70
|
|
71
|
+
def _cast_type(value, target_type):
|
72
|
+
origin = get_origin(target_type)
|
73
|
+
args = get_args(target_type)
|
74
|
+
|
75
|
+
# Handle Optional[T] or Union[T1, T2, ...]
|
76
|
+
if origin is Union:
|
77
|
+
# Optional[str] is Union[str, NoneType]
|
78
|
+
for typ in args:
|
79
|
+
if typ is type(None):
|
80
|
+
continue # skip NoneType
|
81
|
+
try:
|
82
|
+
return _cast_type(value, typ)
|
83
|
+
except (ValueError, TypeError):
|
84
|
+
continue
|
85
|
+
raise ValueError(f"Cannot cast {value!r} to any of {args}")
|
86
|
+
|
87
|
+
# Handle base types
|
88
|
+
if target_type == bool:
|
89
|
+
return value.lower() in ('true', '1', 'yes', 'on', True)
|
90
|
+
elif target_type == int:
|
91
|
+
return int(value)
|
92
|
+
elif target_type == float:
|
93
|
+
return float(value)
|
94
|
+
elif target_type == str:
|
95
|
+
return value
|
96
|
+
else:
|
97
|
+
raise TypeError(f"Unsupported type: {target_type}")
|
98
|
+
|
99
|
+
@dataclass
|
100
|
+
class EmailConfig(ConfigValue):
|
101
|
+
smtp_server: Optional[str] = field(metadata={'env_var': 'SCHD_SMTP_SERVER'}, default=None)
|
102
|
+
smtp_user: Optional[str] = field(metadata={'env_var': 'SCHD_SMTP_USER'}, default=None)
|
103
|
+
smtp_password: Optional[str] = field(metadata={'env_var': 'SCHD_SMTP_PASS'}, default=None)
|
104
|
+
from_addr: Optional[str] = field(metadata={'env_var': 'SCHD_SMTP_FROM'}, default=None)
|
105
|
+
to_addr: Optional[str] = field(metadata={'env_var': 'SCHD_SMTP_TO'}, default=None)
|
106
|
+
smtp_port: int = field(metadata={'env_var': 'SCHD_SMTP_PORT'}, default=25)
|
107
|
+
smtp_starttls: bool = field(metadata={'env_var': 'SCHD_SMTP_TLS'}, default=False)
|
108
|
+
|
66
109
|
|
67
110
|
@dataclass
|
68
111
|
class JobConfig(ConfigValue):
|
@@ -80,6 +123,7 @@ class SchdConfig(ConfigValue):
|
|
80
123
|
scheduler_cls: str = 'LocalScheduler'
|
81
124
|
scheduler_remote_host: Optional[str] = None
|
82
125
|
worker_name: str = 'local'
|
126
|
+
email: EmailConfig = field(default_factory=lambda: EmailConfig.from_dict({}))
|
83
127
|
|
84
128
|
def __getitem__(self,key):
|
85
129
|
# compatible to old fashion config['key']
|
@@ -89,13 +133,19 @@ class SchdConfig(ConfigValue):
|
|
89
133
|
raise KeyError(key)
|
90
134
|
|
91
135
|
|
92
|
-
|
93
|
-
if config_file is None and 'SCHD_CONFIG' in os.environ:
|
94
|
-
config_file = os.environ['SCHD_CONFIG']
|
136
|
+
class ConfigFileNotFound(Exception):...
|
95
137
|
|
96
|
-
if config_file is None:
|
97
|
-
config_file = 'conf/schd.yaml'
|
98
138
|
|
99
|
-
|
139
|
+
def read_config(config_file=None) -> SchdConfig:
|
140
|
+
if config_file:
|
141
|
+
config_filepath = config_file
|
142
|
+
elif 'SCHD_CONFIG' in os.environ:
|
143
|
+
config_filepath = os.environ['SCHD_CONFIG']
|
144
|
+
elif os.path.exists('conf/schd.yaml'):
|
145
|
+
config_filepath = 'conf/schd.yaml'
|
146
|
+
else:
|
147
|
+
raise ConfigFileNotFound()
|
148
|
+
|
149
|
+
with open(config_filepath, 'r', encoding='utf8') as f:
|
100
150
|
config = SchdConfig.from_dict(yaml.load(f, Loader=yaml.FullLoader))
|
101
151
|
return config
|
schd-0.1.1/schd/email.py
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
import smtplib
|
2
|
+
from email.message import EmailMessage
|
3
|
+
import logging
|
4
|
+
from typing import List, Optional, Union
|
5
|
+
import os
|
6
|
+
from pathlib import Path
|
7
|
+
from schd.config import EmailConfig
|
8
|
+
|
9
|
+
logger = logging.getLogger(__name__)
|
10
|
+
|
11
|
+
|
12
|
+
class EmailService:
|
13
|
+
def __init__(self, smtp_server: str, smtp_user: str, smtp_password: str,
|
14
|
+
from_addr: str, smtp_port: int = 25, smtp_starttls: bool = False):
|
15
|
+
self.smtp_server = smtp_server
|
16
|
+
self.smtp_user = smtp_user
|
17
|
+
self.smtp_password = smtp_password
|
18
|
+
self.from_addr = from_addr
|
19
|
+
self.smtp_port = smtp_port
|
20
|
+
self.smtp_starttls = smtp_starttls
|
21
|
+
|
22
|
+
def send_mail(self, title: str, content: str, to_emails: Union[str, List[str]],
|
23
|
+
attachments: Optional[List[str]] = None,
|
24
|
+
content_html: Optional[str] = None,
|
25
|
+
cc_emails: Optional[List[str]] = None,
|
26
|
+
bcc_emails: Optional[List[str]] = None):
|
27
|
+
msg = EmailMessage()
|
28
|
+
msg['Subject'] = title
|
29
|
+
msg['From'] = self.from_addr
|
30
|
+
if isinstance(to_emails, str):
|
31
|
+
to_emails = [to_emails]
|
32
|
+
msg['To'] = ', '.join(to_emails)
|
33
|
+
if cc_emails:
|
34
|
+
msg['Cc'] = ', '.join(cc_emails)
|
35
|
+
|
36
|
+
recipients = to_emails + (cc_emails or []) + (bcc_emails or [])
|
37
|
+
|
38
|
+
# Add text and HTML
|
39
|
+
if content_html:
|
40
|
+
msg.set_content(content)
|
41
|
+
msg.add_alternative(content_html, subtype='html')
|
42
|
+
else:
|
43
|
+
msg.set_content(content)
|
44
|
+
|
45
|
+
# Attach files
|
46
|
+
for filepath in attachments or []:
|
47
|
+
file_path = Path(filepath)
|
48
|
+
with open(file_path, 'rb') as f:
|
49
|
+
file_data = f.read()
|
50
|
+
msg.add_attachment(file_data, maintype='application', subtype='octet-stream', filename=file_path.name)
|
51
|
+
|
52
|
+
# Send email
|
53
|
+
with smtplib.SMTP(self.smtp_server, self.smtp_port) as server:
|
54
|
+
if self.smtp_starttls:
|
55
|
+
server.starttls()
|
56
|
+
if self.smtp_user and self.smtp_password:
|
57
|
+
server.login(self.smtp_user, self.smtp_password)
|
58
|
+
else:
|
59
|
+
logger.info('no username/pass, skip logging in.')
|
60
|
+
server.send_message(msg, from_addr=self.from_addr, to_addrs=recipients)
|
61
|
+
|
62
|
+
@classmethod
|
63
|
+
def from_config(cls, config: 'EmailConfig') -> 'EmailService':
|
64
|
+
return cls(
|
65
|
+
smtp_server=config.smtp_server,
|
66
|
+
smtp_user=config.smtp_user,
|
67
|
+
smtp_password=config.smtp_password,
|
68
|
+
from_addr=config.from_addr,
|
69
|
+
smtp_port=config.smtp_port,
|
70
|
+
smtp_starttls=config.smtp_starttls
|
71
|
+
)
|
@@ -5,6 +5,7 @@ import logging
|
|
5
5
|
import importlib
|
6
6
|
import io
|
7
7
|
import os
|
8
|
+
import socket
|
8
9
|
import sys
|
9
10
|
from typing import Any, Optional, Dict
|
10
11
|
import smtplib
|
@@ -16,6 +17,7 @@ from apscheduler.schedulers.blocking import BlockingScheduler
|
|
16
17
|
from apscheduler.triggers.cron import CronTrigger
|
17
18
|
from apscheduler.executors.pool import ThreadPoolExecutor
|
18
19
|
from schd import __version__ as schd_version
|
20
|
+
from schd.email import EmailService
|
19
21
|
from schd.schedulers.remote import RemoteScheduler
|
20
22
|
from schd.util import ensure_bool
|
21
23
|
from schd.job import Job, JobContext, JobExecutionResult
|
@@ -179,7 +181,7 @@ class ConsoleErrorNotifier:
|
|
179
181
|
|
180
182
|
|
181
183
|
class LocalScheduler:
|
182
|
-
def __init__(self, max_concurrent_jobs: int = 10):
|
184
|
+
def __init__(self, config:SchdConfig, max_concurrent_jobs: int = 10):
|
183
185
|
"""
|
184
186
|
Initialize the LocalScheduler with support for concurrent job execution.
|
185
187
|
|
@@ -190,6 +192,9 @@ class LocalScheduler:
|
|
190
192
|
}
|
191
193
|
self.scheduler = BlockingScheduler(executors=executors)
|
192
194
|
self._jobs:Dict[str, Job] = {}
|
195
|
+
self.email_service = EmailService.from_config(config.email)
|
196
|
+
self.to_mail = config.email.to_addr
|
197
|
+
self.worker_name = config.worker_name or socket.gethostname()
|
193
198
|
logger.info("LocalScheduler initialized in 'local' mode with concurrency support")
|
194
199
|
|
195
200
|
async def init(self):
|
@@ -234,8 +239,13 @@ class LocalScheduler:
|
|
234
239
|
logger.exception('error when executing job, %s', ex)
|
235
240
|
ret_code = -1
|
236
241
|
|
242
|
+
output = output_stream.getvalue()
|
237
243
|
logger.info('job %s execute complete: %d', job_name, ret_code)
|
238
|
-
logger.info('job %s process output: \n%s', job_name,
|
244
|
+
logger.info('job %s process output: \n%s', job_name, output)
|
245
|
+
if ret_code != 0 and self.to_mail:
|
246
|
+
self.email_service.send_mail('job failed %s %s' % (self.worker_name, job_name),
|
247
|
+
content=output,
|
248
|
+
to_emails=self.to_mail)
|
239
249
|
|
240
250
|
def run(self):
|
241
251
|
"""
|
@@ -255,7 +265,7 @@ def build_scheduler(config:SchdConfig):
|
|
255
265
|
scheduler_cls = os.environ.get('SCHD_SCHEDULER_CLS') or config.scheduler_cls
|
256
266
|
|
257
267
|
if scheduler_cls == 'LocalScheduler':
|
258
|
-
scheduler = LocalScheduler()
|
268
|
+
scheduler = LocalScheduler(config)
|
259
269
|
elif scheduler_cls == 'RemoteScheduler':
|
260
270
|
logger.info('scheduler_cls: %s', scheduler_cls)
|
261
271
|
scheduler_remote_host = os.environ.get('SCHD_SCHEDULER_REMOTE_HOST') or config.scheduler_remote_host
|
@@ -270,8 +280,7 @@ def build_scheduler(config:SchdConfig):
|
|
270
280
|
return scheduler
|
271
281
|
|
272
282
|
|
273
|
-
async def run_daemon(
|
274
|
-
config = read_config(config_file=config_file)
|
283
|
+
async def run_daemon(config):
|
275
284
|
scheduler = build_scheduler(config)
|
276
285
|
await scheduler.init()
|
277
286
|
|
@@ -319,11 +328,12 @@ async def main():
|
|
319
328
|
parser.add_argument('--logfile')
|
320
329
|
parser.add_argument('--config', '-c')
|
321
330
|
args = parser.parse_args()
|
322
|
-
config_file = args.config
|
323
331
|
|
324
332
|
logging.basicConfig(level=logging.DEBUG)
|
325
333
|
|
326
|
-
|
334
|
+
config = read_config(args.config)
|
335
|
+
print(f'starting schd, {schd_version}')
|
336
|
+
|
327
337
|
|
328
338
|
if args.logfile:
|
329
339
|
log_stream = open(args.logfile, 'a', encoding='utf8')
|
@@ -333,7 +343,7 @@ async def main():
|
|
333
343
|
log_stream = sys.stdout
|
334
344
|
|
335
345
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(name)s - %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', stream=log_stream)
|
336
|
-
await run_daemon(
|
346
|
+
await run_daemon(config)
|
337
347
|
|
338
348
|
|
339
349
|
if __name__ == '__main__':
|
@@ -1,8 +1,11 @@
|
|
1
|
-
Metadata-Version: 2.
|
2
|
-
Name: schd
|
3
|
-
Version: 0.
|
4
|
-
Home-page: https://github.com/kevenli/schd
|
5
|
-
License: ApacheV2
|
6
|
-
Requires-Dist: apscheduler<4.0
|
7
|
-
Requires-Dist: pyaml
|
8
|
-
Requires-Dist: aiohttp
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: schd
|
3
|
+
Version: 0.1.1
|
4
|
+
Home-page: https://github.com/kevenli/schd
|
5
|
+
License: ApacheV2
|
6
|
+
Requires-Dist: apscheduler<4.0
|
7
|
+
Requires-Dist: pyaml
|
8
|
+
Requires-Dist: aiohttp
|
9
|
+
Dynamic: home-page
|
10
|
+
Dynamic: license
|
11
|
+
Dynamic: requires-dist
|
@@ -1,9 +1,9 @@
|
|
1
|
-
LICENSE
|
2
1
|
README.md
|
3
2
|
setup.cfg
|
4
3
|
setup.py
|
5
4
|
schd/__init__.py
|
6
5
|
schd/config.py
|
6
|
+
schd/email.py
|
7
7
|
schd/job.py
|
8
8
|
schd/scheduler.py
|
9
9
|
schd/util.py
|
@@ -19,7 +19,10 @@ schd/cmds/daemon.py
|
|
19
19
|
schd/cmds/jobs.py
|
20
20
|
schd/cmds/run.py
|
21
21
|
schd/cmds/schd.py
|
22
|
+
schd/cmds/scsendmail.py
|
22
23
|
schd/schedulers/__init__.py
|
23
24
|
schd/schedulers/remote.py
|
25
|
+
tests/test_config.py
|
26
|
+
tests/test_email.py
|
24
27
|
tests/test_scheduler.py
|
25
28
|
tests/test_util.py
|
@@ -1,7 +1,7 @@
|
|
1
|
-
[metadata]
|
2
|
-
license_files = LICENSE
|
3
|
-
|
4
|
-
[egg_info]
|
5
|
-
tag_build =
|
6
|
-
tag_date = 0
|
7
|
-
|
1
|
+
[metadata]
|
2
|
+
license_files = LICENSE
|
3
|
+
|
4
|
+
[egg_info]
|
5
|
+
tag_build =
|
6
|
+
tag_date = 0
|
7
|
+
|
@@ -7,13 +7,14 @@ def read_requirements():
|
|
7
7
|
|
8
8
|
setup(
|
9
9
|
name="schd",
|
10
|
-
version="0.
|
10
|
+
version="0.1.1",
|
11
11
|
url="https://github.com/kevenli/schd",
|
12
12
|
packages=find_packages(exclude=('tests', 'tests.*')),
|
13
13
|
install_requires=['apscheduler<4.0', 'pyaml', 'aiohttp'],
|
14
14
|
entry_points={
|
15
15
|
'console_scripts': [
|
16
16
|
'schd = schd.cmds.schd:main',
|
17
|
+
'scsendmail = schd.cmds.scsendmail:main',
|
17
18
|
],
|
18
19
|
},
|
19
20
|
license="ApacheV2",
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import unittest
|
2
|
+
from schd.config import SchdConfig, JobConfig
|
3
|
+
|
4
|
+
class TestSchdConfig(unittest.TestCase):
|
5
|
+
def setUp(self):
|
6
|
+
self.config = SchdConfig(
|
7
|
+
jobs={"job1": JobConfig(cls='', cron='* * * * *')},
|
8
|
+
scheduler_cls="RemoteScheduler",
|
9
|
+
scheduler_remote_host="10.0.0.1",
|
10
|
+
worker_name="remote_worker"
|
11
|
+
)
|
12
|
+
|
13
|
+
def test_get_existing_field(self):
|
14
|
+
self.assertEqual(self.config["scheduler_cls"], "RemoteScheduler")
|
15
|
+
self.assertEqual(self.config["worker_name"], "remote_worker")
|
16
|
+
self.assertEqual(self.config["scheduler_remote_host"], "10.0.0.1")
|
17
|
+
|
18
|
+
def test_jobs_access(self):
|
19
|
+
self.assertIn("job1", self.config.jobs)
|
20
|
+
self.assertEqual(self.config.jobs['job1'].cls, '')
|
21
|
+
# self.assertEqual(self.config["jobs"]["job1"].name, "job1")
|
22
|
+
|
23
|
+
def test_invalid_key_raises(self):
|
24
|
+
with self.assertRaises(KeyError):
|
25
|
+
_ = self.config["nonexistent"]
|
26
|
+
|
27
|
+
def test_attribute_access_still_works(self):
|
28
|
+
self.assertEqual(self.config.scheduler_cls, "RemoteScheduler")
|
29
|
+
self.assertEqual(self.config.worker_name, "remote_worker")
|
@@ -0,0 +1,68 @@
|
|
1
|
+
import os
|
2
|
+
import unittest
|
3
|
+
from unittest.mock import patch
|
4
|
+
from schd.config import EmailConfig
|
5
|
+
from schd.email import EmailService
|
6
|
+
|
7
|
+
|
8
|
+
class EmailConfigTest(unittest.TestCase):
|
9
|
+
def test_empty(self):
|
10
|
+
target = EmailConfig()
|
11
|
+
self.assertIsNone(target.smtp_server)
|
12
|
+
self.assertIsNone(target.smtp_user)
|
13
|
+
self.assertIsNone(target.smtp_password)
|
14
|
+
self.assertIsNone(target.from_addr)
|
15
|
+
self.assertIsNone(target.to_addr)
|
16
|
+
self.assertEqual(target.smtp_port, 25)
|
17
|
+
self.assertEqual(target.smtp_starttls, False)
|
18
|
+
|
19
|
+
@patch.dict(os.environ, {"SCHD_SMTP_SERVER": "smtp.test.com"}, clear=True)
|
20
|
+
def test_env_var_override(self):
|
21
|
+
config = EmailConfig.from_dict(dict(
|
22
|
+
smtp_server="default.server",
|
23
|
+
smtp_user="user",
|
24
|
+
smtp_password="pass",
|
25
|
+
from_addr="from@example.com",
|
26
|
+
to_addr="to@example.com"
|
27
|
+
))
|
28
|
+
|
29
|
+
# value should have been overrided by environ variable
|
30
|
+
self.assertEqual(config.smtp_server, "smtp.test.com")
|
31
|
+
self.assertEqual(config.smtp_user, "user") # not from env, uses instance value
|
32
|
+
|
33
|
+
@patch.dict(os.environ, {"SCHD_SMTP_PORT": "589"}, clear=False)
|
34
|
+
def test_env_port_type(self):
|
35
|
+
# call `from_dict` to let env_var override effective
|
36
|
+
config = EmailConfig.from_dict(dict(
|
37
|
+
smtp_server="default.server",
|
38
|
+
smtp_user="user",
|
39
|
+
smtp_password="pass",
|
40
|
+
from_addr="from@example.com",
|
41
|
+
to_addr="to@example.com"
|
42
|
+
))
|
43
|
+
|
44
|
+
self.assertEqual(config.smtp_port, 589)
|
45
|
+
|
46
|
+
@patch.dict(os.environ, {"SCHD_SMTP_TLS": "true"}, clear=False)
|
47
|
+
def test_env_tls_type(self):
|
48
|
+
config = EmailConfig.from_dict(dict(
|
49
|
+
smtp_server="default.server",
|
50
|
+
smtp_user="user",
|
51
|
+
smtp_password="pass",
|
52
|
+
from_addr="from@example.com",
|
53
|
+
to_addr="to@example.com"
|
54
|
+
))
|
55
|
+
|
56
|
+
self.assertEqual(config.smtp_starttls, True)
|
57
|
+
|
58
|
+
|
59
|
+
class EmailServiceTest(unittest.TestCase):
|
60
|
+
def test_send_email(self):
|
61
|
+
config = EmailConfig.from_dict(dict())
|
62
|
+
service = EmailService.from_config(config)
|
63
|
+
try:
|
64
|
+
recipient = os.environ['SCHD_SMTP_TO']
|
65
|
+
except KeyError:
|
66
|
+
raise unittest.SkipTest('SCHD_SMTP_TO env not specified, skip test')
|
67
|
+
|
68
|
+
service.send_mail('test', 'test_content', recipient)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import unittest
|
2
2
|
from contextlib import redirect_stdout
|
3
3
|
import io
|
4
|
-
from schd.config import JobConfig
|
4
|
+
from schd.config import JobConfig, read_config
|
5
5
|
from schd.scheduler import LocalScheduler, build_job
|
6
6
|
|
7
7
|
|
@@ -31,8 +31,9 @@ class RedirectStdoutTest(unittest.TestCase):
|
|
31
31
|
class LocalSchedulerTest(unittest.IsolatedAsyncioTestCase):
|
32
32
|
async def test_add_execute(self):
|
33
33
|
job = TestOutputJob()
|
34
|
-
|
35
|
-
|
34
|
+
config = read_config('tests/conf/schd.yaml')
|
35
|
+
target = LocalScheduler(config)
|
36
|
+
await target.add_job(job, 'test_job', config.jobs['ls'])
|
36
37
|
target.execute_job("test_job")
|
37
38
|
|
38
39
|
|
schd-0.0.16/LICENSE
DELETED
@@ -1,201 +0,0 @@
|
|
1
|
-
Apache License
|
2
|
-
Version 2.0, January 2004
|
3
|
-
http://www.apache.org/licenses/
|
4
|
-
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
-
|
7
|
-
1. Definitions.
|
8
|
-
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
-
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
-
the copyright owner that is granting the License.
|
14
|
-
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
-
other entities that control, are controlled by, or are under common
|
17
|
-
control with that entity. For the purposes of this definition,
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
19
|
-
direction or management of such entity, whether by contract or
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
-
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
-
exercising permissions granted by this License.
|
25
|
-
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
27
|
-
including but not limited to software source code, documentation
|
28
|
-
source, and configuration files.
|
29
|
-
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
31
|
-
transformation or translation of a Source form, including but
|
32
|
-
not limited to compiled object code, generated documentation,
|
33
|
-
and conversions to other media types.
|
34
|
-
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
36
|
-
Object form, made available under the License, as indicated by a
|
37
|
-
copyright notice that is included in or attached to the work
|
38
|
-
(an example is provided in the Appendix below).
|
39
|
-
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
-
the Work and Derivative Works thereof.
|
47
|
-
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
49
|
-
the original version of the Work and any modifications or additions
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
-
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
64
|
-
subsequently incorporated within the Work.
|
65
|
-
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
72
|
-
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
-
where such license applies only to those patent claims licensable
|
79
|
-
by such Contributor that are necessarily infringed by their
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
82
|
-
institute patent litigation against any entity (including a
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
85
|
-
or contributory patent infringement, then any patent licenses
|
86
|
-
granted to You under this License for that Work shall terminate
|
87
|
-
as of the date such litigation is filed.
|
88
|
-
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
91
|
-
modifications, and in Source or Object form, provided that You
|
92
|
-
meet the following conditions:
|
93
|
-
|
94
|
-
(a) You must give any other recipients of the Work or
|
95
|
-
Derivative Works a copy of this License; and
|
96
|
-
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
98
|
-
stating that You changed the files; and
|
99
|
-
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
102
|
-
attribution notices from the Source form of the Work,
|
103
|
-
excluding those notices that do not pertain to any part of
|
104
|
-
the Derivative Works; and
|
105
|
-
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
108
|
-
include a readable copy of the attribution notices contained
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
111
|
-
of the following places: within a NOTICE text file distributed
|
112
|
-
as part of the Derivative Works; within the Source form or
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
114
|
-
within a display generated by the Derivative Works, if and
|
115
|
-
wherever such third-party notices normally appear. The contents
|
116
|
-
of the NOTICE file are for informational purposes only and
|
117
|
-
do not modify the License. You may add Your own attribution
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
120
|
-
that such additional attribution notices cannot be construed
|
121
|
-
as modifying the License.
|
122
|
-
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
124
|
-
may provide additional or different license terms and conditions
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
128
|
-
the conditions stated in this License.
|
129
|
-
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
133
|
-
this License, without any additional terms or conditions.
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
-
the terms of any separate license agreement you may have executed
|
136
|
-
with Licensor regarding such Contributions.
|
137
|
-
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
140
|
-
except as required for reasonable and customary use in describing the
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
-
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
152
|
-
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
158
|
-
incidental, or consequential damages of any character arising as a
|
159
|
-
result of this License or out of the use or inability to use the
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
162
|
-
other commercial damages or losses), even if such Contributor
|
163
|
-
has been advised of the possibility of such damages.
|
164
|
-
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
-
or other liability obligations and/or rights consistent with this
|
169
|
-
License. However, in accepting such obligations, You may act only
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
174
|
-
of your accepting any such warranty or additional liability.
|
175
|
-
|
176
|
-
END OF TERMS AND CONDITIONS
|
177
|
-
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
179
|
-
|
180
|
-
To apply the Apache License to your work, attach the following
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
-
replaced with your own identifying information. (Don't include
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
184
|
-
comment syntax for the file format. We also recommend that a
|
185
|
-
file or class name and description of purpose be included on the
|
186
|
-
same "printed page" as the copyright notice for easier
|
187
|
-
identification within third-party archives.
|
188
|
-
|
189
|
-
Copyright [yyyy] [name of copyright owner]
|
190
|
-
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
-
you may not use this file except in compliance with the License.
|
193
|
-
You may obtain a copy of the License at
|
194
|
-
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
-
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
-
See the License for the specific language governing permissions and
|
201
|
-
limitations under the License.
|
schd-0.0.16/schd/__init__.py
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
__version__ = '0.0.16'
|
schd-0.0.16/schd/cmds/jobs.py
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
list jobs
|
3
|
-
"""
|
4
|
-
|
5
|
-
from schd.scheduler import read_config
|
6
|
-
from .base import CommandBase
|
7
|
-
|
8
|
-
|
9
|
-
class JobsCommand(CommandBase):
|
10
|
-
def add_arguments(self, parser):
|
11
|
-
parser.add_argument('--config', '-c', default=None, help='config file')
|
12
|
-
|
13
|
-
def run(self, args):
|
14
|
-
config = read_config(config_file=args.config)
|
15
|
-
for job_name, _ in config.jobs.items():
|
16
|
-
print(job_name)
|
schd-0.0.16/schd/cmds/run.py
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
import logging
|
2
|
-
from schd.cmds.base import CommandBase
|
3
|
-
from schd.scheduler import build_job, read_config, JobContext
|
4
|
-
|
5
|
-
|
6
|
-
def run_job(config_file, job_name):
|
7
|
-
config = read_config(config_file)
|
8
|
-
|
9
|
-
job_config = config.jobs[job_name]
|
10
|
-
|
11
|
-
job = build_job(job_name, job_config.cls, job_config)
|
12
|
-
job_context = JobContext(job_name)
|
13
|
-
job_context.output_to_console = True
|
14
|
-
job(context=job_context)
|
15
|
-
|
16
|
-
|
17
|
-
class RunCommand(CommandBase):
|
18
|
-
def add_arguments(self, parser):
|
19
|
-
parser.add_argument('job')
|
20
|
-
parser.add_argument('--config', '-c')
|
21
|
-
|
22
|
-
def run(self, args):
|
23
|
-
logging.basicConfig(level=logging.INFO)
|
24
|
-
job_name = args.job
|
25
|
-
config_file = args.config
|
26
|
-
run_job(config_file, job_name)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|