Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(component,schedule): introduce schedule component #897

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/init/definitionupdater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
func UpdateComponentDefinitionIndex(ctx context.Context, repo repository.Repository) error {
logger, _ := logger.GetZapLogger(ctx)

defs := componentstore.Init(logger, nil, nil, nil).ListDefinitions(nil, true)
defs := componentstore.Init(componentstore.InitParams{
Logger: logger,
}).ListDefinitions(nil, true)
for _, def := range defs {

if err := updateComponentDefinition(ctx, def, repo); err != nil {
Expand Down
5 changes: 4 additions & 1 deletion cmd/init/presetdownloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ func DownloadPresetPipelines(ctx context.Context, repo repository.Repository) er
if err != nil {
return err
}
componentStore := store.Init(logger, config.Config.Component.Secrets, nil, nil)
componentStore := store.Init(store.InitParams{
Logger: logger,
Secrets: config.Config.Component.Secrets,
})

converter := service.NewConverter(service.ConverterConfig{
MgmtClient: mgmtPrivateServiceClient,
Expand Down
8 changes: 7 additions & 1 deletion cmd/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,12 @@ func main() {

binaryFetcher := external.NewArtifactBinaryFetcher(artifactPrivateServiceClient, minioxClientWrapper)

compStore := componentstore.Init(logger, config.Config.Component.Secrets, nil, binaryFetcher)
compStore := componentstore.Init(componentstore.InitParams{
Logger: logger,
Secrets: config.Config.Component.Secrets,
BinaryFetcher: binaryFetcher,
TemporalClient: temporalClient,
})
workerUID, _ := uuid.NewV4()

service := service.NewService(
Expand Down Expand Up @@ -469,6 +474,7 @@ func main() {
ArtifactPublicServiceClient: artifactPublicServiceClient,
ArtifactPrivateServiceClient: artifactPrivateServiceClient,
BinaryFetcher: binaryFetcher,
PipelinePublicServiceClient: pipelinePublicServiceClient,
},
)

Expand Down
2 changes: 1 addition & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ database:
host: pg-sql
port: 5432
name: pipeline
version: 37
version: 38
timezone: Etc/UTC
pool:
idleconnections: 5
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Will do it in ins-6969
package smartlead
package smartlead
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Will do it in ins-6969
package smartlead
package smartlead
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Will do it in ins-6969
package smartlead
package smartlead
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Will do it in ins-6969
package smartlead
package smartlead
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Will do it in ins-6969
package smartlead
package smartlead
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Will do it in ins-6969
package smartlead
package smartlead
4 changes: 3 additions & 1 deletion pkg/component/base/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"google.golang.org/protobuf/types/known/structpb"

jsoniter "github.com/json-iterator/go"
temporalclient "go.temporal.io/sdk/client"

"github.com/instill-ai/pipeline-backend/pkg/component/internal/jsonref"
"github.com/instill-ai/pipeline-backend/pkg/data/format"
Expand Down Expand Up @@ -174,7 +175,8 @@ type Component struct {
inputAcceptFormatsFields map[string]map[string][]string
outputFormatsFields map[string]map[string]string

BinaryFetcher external.BinaryFetcher
BinaryFetcher external.BinaryFetcher
TemporalClient temporalclient.Client
}

// IdentifyEvent is not implemented for the base component.
Expand Down
2 changes: 1 addition & 1 deletion pkg/component/generic/collection/v0/config/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,4 @@
"type": "object"
}
}
}
}
19 changes: 19 additions & 0 deletions pkg/component/generic/schedule/v0/.compogen/bottom.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Supported events

### Cron Job Triggered Event

An event triggered on a cron job.

<div class="markdown-col-no-wrap" data-col-1 data-col-2>

| Configuration | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Cron Expression | `cron` | string | A cron expression in standard 5-field format (minute hour day-of-month month day-of-week) |
</div>

<div class="markdown-col-no-wrap" data-col-1 data-col-2>

| Event Message | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Triggered At | `triggered-at` | string | The ISO 8601 timestamp when the cron job was triggered |
</div>
49 changes: 49 additions & 0 deletions pkg/component/generic/schedule/v0/README.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: "Schedule"
lang: "en-US"
draft: false
description: "Learn about how to set up a VDP Schedule component https://github.com/instill-ai/instill-core"
---

The Schedule component is a generic component that allows users to trigger pipelines on a schedule using cron expressions.
It can carry out the following tasks:



## Release Stage

`Alpha`



## Configuration

The component definition and tasks are defined in the [definition.json](https://github.com/instill-ai/pipeline-backend/blob/main/pkg/component/generic/schedule/v0/config/definition.json) and [tasks.json](https://github.com/instill-ai/pipeline-backend/blob/main/pkg/component/generic/schedule/v0/config/tasks.json) files respectively.






## Supported Tasks


## Supported events

### Cron Job Triggered Event

An event triggered on a cron job.

<div class="markdown-col-no-wrap" data-col-1 data-col-2>

| Configuration | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Cron Expression | `cron` | string | A cron expression in standard 5-field format (minute hour day-of-month month day-of-week) |
</div>

<div class="markdown-col-no-wrap" data-col-1 data-col-2>

| Event Message | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Triggered At | `triggered-at` | string | The ISO 8601 timestamp when the cron job was triggered |
</div>
16 changes: 16 additions & 0 deletions pkg/component/generic/schedule/v0/config/definition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"availableTasks": [],
"documentationUrl": "https://www.instill.tech/docs/component/generic/schedule",
"icon": "assets/schedule.svg",
"id": "schedule",
"public": true,
"title": "Schedule",
"vendor": "Generic",
"description": "Trigger pipelines on a schedule using cron expressions.",
"tombstone": false,
"type": "COMPONENT_TYPE_GENERIC",
"uid": "f2a89c6d-e315-4b7a-9d8f-c83e45a92c10",
"version": "0.1.0",
"sourceUrl": "https://github.com/instill-ai/pipeline-backend/blob/main/pkg/component/generic/schedule/v0",
"releaseStage": "RELEASE_STAGE_ALPHA"
}
36 changes: 36 additions & 0 deletions pkg/component/generic/schedule/v0/config/events.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"EVENT_CRON_JOB_TRIGGERED": {
"title": "Cron Job Triggered Event",
"description": "An event triggered on a cron job",
"configSchema": {
"type": "object",
"required": ["cron"],
"properties": {
"cron": {
"type": "string",
"pattern": "^[0-9*,-/]+\\s+[0-9*,-/]+\\s+[0-9*,-/]+\\s+[0-9*,-/]+\\s+[0-9*,-/]+$"
}
}
},
"messageSchema": {
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"required": [
"triggered-at"
],
"properties": {
"triggered-at": {
"type": "string",
"description": "The ISO 8601 timestamp when the cron job was triggered"
}
},
"additionalProperties": false,
"title": "Cron job triggered event"
},
"messageExamples": [
{
"triggered-at": "2024-01-01T00:00:00.000Z"
}
]
}
}
1 change: 1 addition & 0 deletions pkg/component/generic/schedule/v0/config/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
16 changes: 16 additions & 0 deletions pkg/component/generic/schedule/v0/event_cron_job_triggered.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package schedule

import (
"context"

"github.com/instill-ai/pipeline-backend/pkg/component/base"
"github.com/instill-ai/pipeline-backend/pkg/data"
)

func (c *component) handleEventCronJobTriggered(ctx context.Context, rawEvent *base.RawEvent) (parsedEvent *base.ParsedEvent, err error) {

return &base.ParsedEvent{
ParsedMessage: rawEvent.Message,
Response: data.Map{},
}, nil
}
10 changes: 10 additions & 0 deletions pkg/component/generic/schedule/v0/event_structs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package schedule

type EventCronJobTriggered struct {
Cron string `instill:"cron"`
}

type EventCronJobTriggeredMessage struct {
UID string `instill:"uid"`
EventID string `instill:"eventID"`
}
Loading
Loading