TLDR; Creating a relationship
Relationships are a fundamental part of Legion. It connect to completely independent functions/services that otherwise don’t integrate
Requirements
LEXs
lex-conditioner
lex-tasker
lex-transformer
lex-lex
Legion::Data to be connected and have access to a database. Relationships are stored in a table so without the table, you can’t have a relationship entry
Instructions, Direct Database
Ensure that the LEXs you want to use have been installed and are registered inside the extensions table(this requires you to run the
lex-lex
extensionAdd a new row inside the relationships data
Required Columns
active(Boolean, default:true): Is this relationship active? If 0, then it won’t create a task for the trigger
trigger_id(Integer): A FK to the functions table to tell you what function triggers this relationship to run
action_id(Integer): A FK to the functions table to tell you what function runs after this relationship is triggered
delay(Integer, default:0): Should we delay execution of this task? A positive number is number of seconds to wait to run.
lex-tasker
must be running otherwise delayed tasks will not be grabbedallow_new_chains(Boolean, default: true): Can this trigger a new chain(injection) or must it be apart of the chain_id defined above
Optional Columns
name(String): the name/description of the relationship. Only used to inform users
chain_id(Integer): A FK to the chains table allowed you to create relationships that are connected
conditions(Text): Conditions which must pass validation in order to send this task to the action
If this is null, empty or < 4 characters long, it will skip the conditioner step automatically and go straight to transformer
See -___- for conditioner examples
transformation(Text): A definition on how to manipulate the data into a format the action function can use
If this is null, empty or < 4 characters long, it will skip the transformer step and automatically go to the output task queue for the action_function
See -___- for transformer examples
debug(Boolean, default:false): Should we add extra task logs for this event. Warning this will add significantly more entries into the last_logs table
lex-tasker
is the extensions that checks for a subtask. Without it, the check subtask queue will begin to fill and relationships won’t be checkedtasker automatically checks for relationships based on the dataset. It is however, cached for either 5 seconds or whatever the cache TTL setting is set to. The reason for this is that if you have hundreds of tasks running, it can get extremely expensive to find subtasks for every task that completes. Allowing this to be cached dramatically increases performance
find_subtask settings
extensions.tasker.find_subtasks_cache_ttl
default = 5extensions.tasker.find_subtasks_cache
default = trueextensions.tasker.find_trigger_cache_ttl
default = 60extensions.tasker.find_trigger_cache
default = true
fetch_delayed settings
extensions.tasker.fetch_delayed.interval
default = 1, it’s worth noting that each worker of tasker will push a refresh message at this interval1 instance, 1 tasker worker, interval = 1, you should see 1 message per second in the
task.fetch_delayed
queue2 instances, 4 tasker workers, interval = 2, you should see ~4 messages per second in the
task.fetch_delayed
queueIt’s worth noting that the fetch_delayed queue uses the
x-single-active-consumer
flag so you don’t have to worry about race conditions and double task queueing
Task Path
task completes sending a message to the
task.subtask.check
queuetasker
grabs all rows out of the relationships table where this function is the triggerit skips all tasks that are not active or don’t meet the chain requirements
if delay is set to 0, skip to step 6
task status is updated to
task.delayed
to be picked up byfetch_delayed
worker once enough time has passedtasker parses all the things for this relationship row including where is this thing going(the action function)
If there are no conditions and
there is a transformation defined, skip to step 9
there is no transformation defined, skip to step 10
Conditioner checks the conditions
if it fails checks, then update status to
conditioner.failed
and process endsif it succeeds and there is not a transformation, skip to step
if it succeeds, continue
transform picks up the task, and runs the transformer engine to insert variables, modify the payload, etc with whatever you defined in the transformation column
task is sent to the queue that the worker users. Each function is associated with a runner. Each runner has a queue name. The task will be sent to the queue with the queue name and routing key will =
extension.runner.function
worker picks up work, completes it and sends a message to
task.subtask.check
to see if there are any relationships for tasker to create work for(repeat the steps)