-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ feat: cli
- Loading branch information
Showing
6 changed files
with
115 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from onestep import step, MemoryBroker, CronBroker | ||
|
||
cron_broker = CronBroker("* * * * * */3", body="hi cron") | ||
|
||
|
||
@step(from_broker=cron_broker) | ||
def cron_job(message): | ||
print(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import argparse | ||
import importlib | ||
import logging | ||
import sys | ||
from onestep import step, __version__ | ||
|
||
LOGFORMAT = "[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s" | ||
|
||
|
||
def setup_logging(): | ||
logging.basicConfig(level=logging.DEBUG, format=LOGFORMAT, stream=sys.stdout) | ||
|
||
# exclude amqpstorm logs | ||
logging.getLogger("amqpstorm").setLevel(logging.CRITICAL) | ||
return logging.getLogger("onestep") | ||
|
||
|
||
logger = setup_logging() | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser( | ||
description='run onestep' | ||
) | ||
parser.add_argument( | ||
"step", | ||
help="the run step", | ||
) | ||
parser.add_argument( | ||
"--group", "-G", default=None, | ||
help="the run group", | ||
type=str | ||
) | ||
parser.add_argument( | ||
"--print", | ||
action="store_true", | ||
help="enable printing") | ||
parser.add_argument( | ||
"--path", "-P", default=".", nargs="*", type=str, | ||
help="the step import path (default: current running directory)" | ||
) | ||
return parser.parse_args() | ||
|
||
|
||
def main(): | ||
args = parse_args() | ||
for path in args.path: | ||
sys.path.insert(0, path) | ||
logger.info(f"OneStep {__version__} is start up.") | ||
try: | ||
importlib.import_module(args.step) | ||
step.start(group=args.group, block=True, print_jobs=args.print) | ||
except KeyboardInterrupt: | ||
step.shutdown() | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters