Skip to content

Hooks

flowtask.hooks

Hooks.

Hooks can be used to dispatch (triggering) actions or tasks when events are received.

Triggers can be loaded/managed by HookService.

actions

Hook Actions.

Actions are the Components called by a Hook Definition.

AbstractAction

AbstractAction(*args, **kwargs)

Bases: MaskSupport, LogSupport, LocaleSupport, ABC

AbstractAction.

Action can be used to perform operations when a Hook is called.

DummyAction

DummyAction(*args, **kwargs)

Bases: AbstractAction

DummyAction.

Simply Print the Action object.

JiraIssue

JiraIssue(*args, **kwargs)

Bases: AbstractAction

An action to process Jira issue events.

JiraTicket

JiraTicket(*args, **kwargs)

Bases: AbstractTicket

Jira.

Create a Jira Ticket using a Hook.

create async
create(hook, *args, **kwargs)

create.

Create a new Ticket.

Task

Task(*args, **kwargs)

Bases: TaskSupport, AbstractAction

Task.

Calling an FlowTask Task.

Zammad

Zammad(*args, **kwargs)

Bases: AbstractTicket, AbstractREST

Zammad.

Managing Tickets using Zammad.

create async
create(hook, *args, **kwargs)

create.

Create a new Ticket.

abstract

AbstractAction
AbstractAction(*args, **kwargs)

Bases: MaskSupport, LogSupport, LocaleSupport, ABC

AbstractAction.

Action can be used to perform operations when a Hook is called.

dummy

DummyAction
DummyAction(*args, **kwargs)

Bases: AbstractAction

DummyAction.

Simply Print the Action object.

jira

JiraIssue
JiraIssue(*args, **kwargs)

Bases: AbstractAction

An action to process Jira issue events.

JiraTicket
JiraTicket(*args, **kwargs)

Bases: AbstractTicket

Jira.

Create a Jira Ticket using a Hook.

create async
create(hook, *args, **kwargs)

create.

Create a new Ticket.

rest

AbstractREST
AbstractREST(hook, *args, **kwargs)

Bases: AbstractAction

AbstractREST.

Base class for actions that interact with REST APIs.

request async
request(url, method='get', data=None, cookies=None, headers=None)

request connect to an http source

session async
session(url=None, method=None, data=None, cookies=None, headers=None)

session. Connect to an http source using aiohttp.

sampledata

ProcessData
ProcessData(*args, **kwargs)

Bases: AbstractAction

ProcessData. Process data received in a webhook event.

run async
run(hook, *args, **kwargs)

Sample Action for Processing uploaded files.

sensor

ProcessSensorData
ProcessSensorData(*args, **kwargs)

Bases: AbstractAction

ProcessSensorData.

WIP example of to process Sensor data from MQTTT service.

task

Task
Task(*args, **kwargs)

Bases: TaskSupport, AbstractAction

Task.

Calling an FlowTask Task.

ticket

AbstractTicket
AbstractTicket(*args, **kwargs)

Bases: AbstractAction

AbstractTicket.

Managing Ticket system using Actions.

create abstractmethod async
create(*args, **kwargs)

create.

Create a new Ticket.

zammad

Zammad
Zammad(*args, **kwargs)

Bases: AbstractTicket, AbstractREST

Zammad.

Managing Tickets using Zammad.

create async
create(hook, *args, **kwargs)

create.

Create a new Ticket.

hook

Hook

Hook(hook)

Hook.

Compile a Hook (Triggers and Actions) and got every step on the hook.

service

Hook Management.

This module is responsible for handling the Hooks in Flowtask.

HookService

HookService(event_loop, app, **kwargs)
add_hook
add_hook(hook)

Add the Hook, start it and calling the Setup.

load_db_hooks async
load_db_hooks()

load_db_hooks.

Load all Hooks saved into the Database.

load_fs_hooks async
load_fs_hooks()

load_fs_hooks.

Load all Hooks from the Task Storage (Filesystem).

setup async
setup()

setup.

Service Configuration.

Args: app (aiohttp.web.Application): Web Application.

start_hooks async
start_hooks(app)

start_hooks.

Starts the Hook Service.

step

StepAction

StepAction(action, params, **kwargs)
run async
run(hook, *args, **kwargs)

Run action involved

types

Hook Types.

Hook Types are triggers that can be executed when an event is triggered.

  1. FSWatchdog: Watches a specified directory for changes.

base

BaseTrigger
BaseTrigger(*args, actions=None, **kwargs)

Bases: MaskSupport, LogSupport, LocaleSupport, ABC

BaseTrigger.

Base class for all Triggers in FlowTask.

setup
setup(app)

setup.

Configuration of Trigger when started.

Args: app (aiohttp.web.Application): Web Application.

brokers

Message Brokers.

Message Brokers are services that allow applications to send and receive messages.

Supported Message Brokers on Flowtask are: - MQTT - SQS - Redis - RabbitMQ

base
BaseMQTrigger
BaseMQTrigger(*args, actions=None, **kwargs)

Bases: BaseTrigger

connect abstractmethod async
connect()

Establish the connection.

disconnect abstractmethod async
disconnect()

Disconnect the connection.

start_consuming abstractmethod async
start_consuming()

Start consuming messages.

rabbitmq
RabbitMQTrigger
RabbitMQTrigger(*args, queue_name, routing_key='', exchange_name='', exchange_type='topic', credentials=None, actions=None, **kwargs)

Bases: BaseMQTrigger

redis
RedisTrigger
RedisTrigger(*args, stream_name, group_name='default_group', consumer_name='default_consumer', credentials=None, actions=None, **kwargs)

Bases: BaseMQTrigger

Redis Trigger.

Trigger that listens to a Redis Stream and calls actions based on the received messages.

fs

FSWatchdog
FSWatchdog(*args, **kwargs)

Bases: BaseWatchdog

FSWatchdog. Checking for changes in the filesystem and dispatch events.

FsHandler
FsHandler(parent, patterns=None, *args, **kwargs)

Bases: PatternMatchingEventHandler

on_modified
on_modified(event)

Handle file modification events.

This method is called when a file modification event is detected. It processes the event and calls the appropriate actions if the event meets certain criteria.

event (FileSystemEvent): The event object containing information about the file modification.

Returns: None

Note: - The method returns early if the event is for a directory or if 'modified' is not in the parent's events list. - It also returns early if the file was recently created to avoid duplicate processing. - If the file has zero size, a warning is logged. - The event is processed and actions are called twice with the same arguments.

process
process(event)

Process the event if it matches the patterns and isn't a directory.

zero_size
zero_size(filepath)

Check if the file is of zero size.

http

HTTPHook
HTTPHook(*args, **kwargs)

Bases: BaseTrigger, BaseHandler

HTTPHook.

Base Hook for all HTTP-based hooks.

jira

JiraIssue

Bases: BaseModel

JiraIssue.

A BaseModel to represent a Jira Issue.

JiraTrigger
JiraTrigger(*args, secret_token=None, **kwargs)

Bases: HTTPHook

JiraTrigger.

A Trigger that handles Jira webhooks for issue events.

mail

EmailTrigger
EmailTrigger(*args, webhook_url, tenant_id=None, client_id=None, client_secret=None, resource=None, **kwargs)

Bases: HTTPHook

authenticate async
authenticate()

Authenticates the client with Azure AD and initializes the Graph client.

This method creates a ClientSecretCredential using the tenant ID, client ID, and client secret. It then sets up an AzureIdentityAuthenticationProvider, initializes a GraphRequestAdapter, and finally creates a GraphServiceClient.

The method doesn't take any parameters as it uses the instance variables for authentication details.

Returns:

Type Description

None

postgres

PostgresTrigger
PostgresTrigger(*args, dsn=None, channel='notifications', **kwargs)

Bases: BaseTrigger

PostgresTrigger.

Trigger that listens for PostgreSQL events and sends notifications. Using LISTEN/NOTIFY Infraestructure.

responses

Responses.

Pre-defined responses for Hooks.

TriggerResponse

Basic Response.

Basic Reponse dispatched by a Hook.

base
TriggerResponse

Basic Response.

Basic Reponse dispatched by a Hook.

sharepoint

SharePointTrigger
SharePointTrigger(*args, webhook_url, tenant_id=None, client_id=None, client_secret=None, resource=None, **kwargs)

Bases: HTTPHook

authenticate async
authenticate()

Authenticates the client with Azure AD and initializes the Graph client.

This method creates a ClientSecretCredential using the tenant ID, client ID, and client secret. It then sets up an AzureIdentityAuthenticationProvider, initializes a GraphRequestAdapter, and finally creates a GraphServiceClient.

The method doesn't take any parameters as it uses the instance variables for authentication details.

Returns:

Type Description

None

ssh

SFTPWatcher
SFTPWatcher(host, port, username, password, path, interval=300, max_retries=5, retry_delay=60, **kwargs)

Bases: BaseWatcher

upload

UploadHook
UploadHook(*args, allowed_mime_types=None, allowed_file_names=None, **kwargs)

Bases: HTTPHook

UploadHook.

A Trigger that handles file uploads via HTTP POST/PUT requests.

watch

BaseWatchdog
BaseWatchdog(*args, **kwargs)

Bases: BaseTrigger

BaseWatchdog. Checking for changes in the filesystem and dispatch events.

web

WebHook
WebHook(*args, **kwargs)

Bases: HTTPHook

WebHook.

Can be used to receive data from a web URL.