CDS Hooks µService is the component designed to run all workflow hooks.
Following hooks are supported:
- Webhook
- Scheduler
Following will be supported:
- Kafka Listener
- GitHub, GitLab, Bitbucket Poller
All hooks are considered as task. Tasks are synchronized on startup with workflow hooks from CDS API, and added on the fly when CDS API call this µService.
When a hook is invocated or have to be invocated, we talk about task execution.
Task execution are managed by an internal scheduler Service.runScheduler(context.Context).
The scheduler is design in three parts:
- the task execution processor
Service.dequeueTaskExecutions(context.Context): To feed it, we have to push a task execution key in the queuehooks:scheduler:queue. - the task execution retry
Service.retryTaskExecutionsRoutine(context.Context): Which checks all executions to push in the queuehooks:scheduler:queuethe not processed task execution - the task execution cleaner
Service.deleteTaskExecutionsRoutine(context.Context): Which removes old task executions.
Task list and definitions are stored in the Cache (Redis or local). The key hooks:tasks is a Sorted Set containing tasks UUID sorted by timestamp creation.
Each task is stored as JSON in a key hooks:tasks:<UUID>.
When a task is or have to be invocated, the task execution of the task is listed in a Sorted Set (sorted by timestamp of task execution): hooks:tasks:executions:<type>:<UUID>; this set contains the list of all timestamp on task execution.
The detail of an task execution is stored as JSON in. The task execution key is hooks:tasks:executions:<type>:<UUID>:<timestamp>
Following routes are available:
-
GET|POST|PUT|DELETE /webhook/{uuid}: Routes available for the webhooks. No authentication. -
POST /task: Create a new task from a CDSsdk.WorkflowNodeHook. Authentication: HeaderX_AUTH_HEADER:<Service Hash>in base64 -
GET|PUT|DELETE /task/{uuid}: Get, Update or Delete a task. Authentication: HeaderX_AUTH_HEADER:<Service Hash>in base64 -
GET /task/{uuid}/execution: Get all task execution. Authentication: HeaderX_AUTH_HEADER:<Service Hash>in base64
The µService is run with a shared.infra token and register on CDS API; on registration, CDS API gives in response a hash (service hash) which must be used to make every call to CDS API. Every 30 seconds, it heartbeats on CDS API.
All the specific code for each type of hook (task) is in the tasks.go file.
- Declare a new const for the type
- Update
hookToTaskfunction which convert a CDSsdk.WorkflowNodeHookto a task - Update
startTaskfunction if you have some thing special to do to start or prepare the next task execution - Update
stopTaskfunction if you have some thing special to do to stop a task - Update
doTaskfunction and create ado<your-stuff>Executionfunction with your business