Skip to content

Commit

Permalink
tmpl: fixed templates and CLI test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Miksus committed Oct 3, 2021
1 parent 68bb098 commit 1082ec8
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 23 deletions.
2 changes: 1 addition & 1 deletion redengine/templates/complex/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
recursive-include my_package/tasks*.yaml
global-include *.yaml
15 changes: 1 addition & 14 deletions redengine/templates/simple/tasks/yaml_tasks/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
my-yaml-task-1:
path: 'funcs.py'
func: 'main'
#start_cond: 'every 1 seconds'
start_cond: 'minutely'
execution: 'main'
parameters:
my_task_param: 'my value' # Function parameter
Expand All @@ -33,16 +33,3 @@ my-yaml-task-2:
path: 'funcs.py'
func: 'do_things' # Runs on another process
execution: 'thread'

# Note also our init hook. Tasks that start with
# 'dev.' won't be run when env='prod' but these
# tasks are only ones allowed to be run if
# env='dev'.

dev.my-yaml-task-2:
path: 'funcs.py'
execution: 'main'
func: 'main'
start_cond: 'every 5 seconds'
parameters:
my_task_param: '(this is dev)' # Function parameter
61 changes: 54 additions & 7 deletions redengine/templates/standalone/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,93 @@
# This file contains a whole scheduling
# system. Useful for simple or quick projects.

import logging

from redengine import Session
from redengine.tasks import FuncTask
from redengine.arguments import FuncArg
from redengine.extensions import Sequence


# Session
# -------

session = Session()
session = Session(
scheme=["log_memory"] # Logging to memory, customize as needed.
)

# Logging
# -------

# You may want to customize the logging.
# You can just add new handlers to the
# task/scheduler logging, like:

# Creating a new handler
formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s")
default_stream = logging.StreamHandler()
default_stream.setFormatter(formatter)
default_stream.setLevel(logging.INFO)

# Setting the handler
task_logger = logging.getLogger(session.config["task_logger_basename"])
sched_logger = logging.getLogger(session.config["scheduler_logger_basename"])
task_logger.addHandler(default_stream)
sched_logger.addHandler(default_stream)


# Tasks
# -----

# Feel free to delete/modify as you wish.

@FuncTask(start_cond="minutely")
def my_pytask_1():
print(f"Executing 'my_pytask_1'...")
...

@FuncTask(start_cond="minutely", execution="main", name="my_pytask_2")
@FuncTask(start_cond="minutely", name="my_pytask_2")
def my_pytask_2(my_session_arg):
print(f"Executing 'my_pytask_2' with param '{my_session_arg}'...")
print(f"Executing 'my_pytask_2' with session param '{my_session_arg}'...")
...

@FuncTask(start_cond="minutely", execution="process", name="my_pytask_3", parameters={"my_param": "a task arg"})
def do_stuff(my_param):
print(f"Executing 'my_pytask_3' with param '{my_param}'...")
@FuncTask(start_cond="minutely", name="my_pytask_3", parameters={"my_param": "a task arg"})
def do_stuff_1(my_param):
print(f"Executing 'my_pytask_3' with task param '{my_param}'...")
...

@FuncTask(start_cond="minutely") # after task 'my_pytask_1'
def my_pytask_4():
print(f"Executing 'my_pytask_4' that depends on 'my_task_1'...")
...

@FuncTask(name="my_pytask_5")
def my_pytask_5():
print(f"Executing 'my_pytask_5' that depends on 'my_task_2' using Sequence...")
...

@FuncTask(start_cond="every 5 sec", name="metatask", execution="thread")
def do_meta_stuff():
print(f"Executing meta task that can operate on the session. (Disables itself)")
session.tasks["metatask"].disabled = True
...


# Arguments
# ---------

@FuncArg.to_session()
def my_session_arg():
print("Getting session argument...")
...
return 'a session arg'


# Pipelines
# ---------

Sequence(["my_pytask_2", "my_pytask_3"], interval="every 10 seconds")
Sequence(["my_pytask_2", "my_pytask_5"], interval="every 10 seconds")


# Starting up
# -----------
Expand Down
2 changes: 1 addition & 1 deletion redengine/test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_start(self, project):
session.set_as_default()

# Make almost instant shutdown
session.scheduler.shut_cond = SchedulerCycles() == 1
session.scheduler.shut_cond = SchedulerCycles() >= 2
session.start()

assert 1 < len(session.tasks)
Expand Down

0 comments on commit 1082ec8

Please sign in to comment.