Skip to content

Commit

Permalink
Refactor AnsibleEvent message
Browse files Browse the repository at this point in the history
  • Loading branch information
benthomasson committed Aug 11, 2023
1 parent a958932 commit 751f0d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
18 changes: 2 additions & 16 deletions ansible_rulebook/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
WorkflowJobTemplateNotFoundException,
)
from .job_template_runner import job_template_runner
from .messages import Action, Job, Shutdown, serialize
from .messages import Action, Job, Shutdown, serialize, AnsibleEvent
from .util import get_horizontal_rule, run_at

logger = logging.getLogger(__name__)
Expand All @@ -72,7 +72,6 @@ async def none(
await event_log.put(
serialize(
Action(
type="Action",
action="noop",
action_uuid=str(uuid.uuid4()),
ruleset=source_ruleset_name,
Expand Down Expand Up @@ -115,7 +114,6 @@ async def debug(event_log, **kwargs):
await event_log.put(
serialize(
Action(
type="Action",
action="debug",
action_uuid=str(uuid.uuid4()),
playbook_name=kwargs.get("name"),
Expand Down Expand Up @@ -159,7 +157,6 @@ async def print_event(
await event_log.put(
serialize(
Action(
type="Action",
action="print_event",
action_uuid=str(uuid.uuid4()),
activation_id=settings.identifier,
Expand Down Expand Up @@ -197,7 +194,6 @@ async def set_fact(
await event_log.put(
serialize(
Action(
type="Action",
action="set_fact",
action_uuid=str(uuid.uuid4()),
activation_id=settings.identifier,
Expand Down Expand Up @@ -241,7 +237,6 @@ async def retract_fact(
await event_log.put(
serialize(
Action(
type="Action",
action="retract_fact",
action_uuid=str(uuid.uuid4()),
ruleset=source_ruleset_name,
Expand Down Expand Up @@ -278,7 +273,6 @@ async def post_event(
await event_log.put(
serialize(
Action(
type="Action",
action="post_event",
action_uuid=str(uuid.uuid4()),
ruleset=source_ruleset_name,
Expand Down Expand Up @@ -342,7 +336,6 @@ async def run_playbook(
await event_log.put(
serialize(
Job(
type="Job",
job_id=job_id,
ansible_rulebook_id=settings.identifier,
name=playbook_name,
Expand Down Expand Up @@ -446,7 +439,6 @@ async def run_module(
await event_log.put(
serialize(
Job(
type="Job",
job_id=job_id,
ansible_rulebook_id=settings.identifier,
name=module_name,
Expand Down Expand Up @@ -538,7 +530,7 @@ async def call_runner(
def event_callback(event, *args, **kwargs):
event["job_id"] = job_id
event["ansible_rulebook_id"] = settings.identifier
queue.sync_q.put(dict(type="AnsibleEvent", event=event))
queue.sync_q.put(serialize(AnsibleEvent(event=event)))

# Here we read the async side and push it into the event queue
# which is also async.
Expand Down Expand Up @@ -703,7 +695,6 @@ async def post_process_runner(

result = serialize(
Action(
type="Action",
action=action,
action_uuid=str(uuid.uuid4()),
activation_id=activation_id,
Expand Down Expand Up @@ -785,7 +776,6 @@ async def run_job_template(
await event_log.put(
serialize(
Job(
type="Job",
job_id=job_id,
ansible_rulebook_id=settings.identifier,
name=name,
Expand Down Expand Up @@ -828,7 +818,6 @@ async def run_job_template(

a_log = serialize(
Action(
type="Action",
action="run_job_template",
action_uuid=str(uuid.uuid4()),
activation_id=settings.identifier,
Expand Down Expand Up @@ -903,7 +892,6 @@ async def run_workflow_template(
await event_log.put(
serialize(
Job(
type="Job",
job_id=job_id,
ansible_rulebook_id=settings.identifier,
name=name,
Expand Down Expand Up @@ -951,7 +939,6 @@ async def run_workflow_template(

a_log = serialize(
Action(
type="Action",
action="run_workflow_template",
action_uuid=str(uuid.uuid4()),
activation_id=settings.identifier,
Expand Down Expand Up @@ -1016,7 +1003,6 @@ async def shutdown(
await event_log.put(
serialize(
Action(
type="Action",
action="shutdown",
action_uuid=str(uuid.uuid4()),
activation_id=settings.identifier,
Expand Down
6 changes: 6 additions & 0 deletions ansible_rulebook/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ class Job:
action: str
type: str = "Job"


@dataclass(frozen=True)
class AnsibleEvent:
event: dict
type: str = "AnsibleEvent"

serialize = asdict

0 comments on commit 751f0d4

Please sign in to comment.