Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A distributed, durable job execution platform

NotificationsYou must be signed in to change notification settings

nikhilbhatia08/taskflow

Repository files navigation

TaskFlow HeroTaskFlow HeroTaskFlow Hero

TaskFlow is an efficient task executor and scheduler which is used to schedule jobs and tasks and multiple workers can pick those tasks and execute them

Usage

Import the taskflow-gosdk:

go get github.com/nikhilbhatia08/taskflow/taskflow-gosdk
package tasksimport ("context""encoding/json""log""fmt""time"taskflowgosdk"github.com/nikhilbhatia08/taskflow/taskflow-gosdk")typeEmailPayloadstruct {EmailSenderIdstringEmailRecieverIdstringEmailBodystring}// Write a function to create a task which consists of queuename, payload and the number of retriesfuncEmailDelivery()error {taskflow,err:=taskflowgosdk.NewServer("localhost:9003","localhost:9002")// The configurations of the jobservice and the queueserviceiferr!=nil {returnerr}payload,err:=json.Marshal(EmailPayload{EmailSenderId:"SomeSenderId",EmailRecieverId:"SomeRecieverId",EmailBody:"Some body"})iferr!=nil {returnerr}taskflow.NewJob(&taskflowgosdk.CreateJobRequest{QueueName:"EmailQueue",Payload:string(payload),Retries:5,})returnnil}

Create a worker and start executing the jobs:

package tasksimport ("context""encoding/json""log""fmt""time"taskflowgosdk"github.com/nikhilbhatia08/taskflow/taskflow-gosdk")typeEmailPayloadstruct {EmailSenderIdstringEmailRecieverIdstringEmailBodystring}// Write a function to create a worker to poll to the task queue and execute the jobsfuncEmailWorker()error {worker,err:=taskflowgosdk.NewServer("localhost:9003","localhost:9002")// The configurations of the jobservice and the queueserviceiferr!=nil {returnerr}worker.Run(&taskflowgosdk.RunConfigurations{QueueName:"EmailQueue",Handler:EmailDeliveryHandler,})returnnil}funcEmailDeliveryHandler(ctx context.Context,emailJob*taskflowgosdk.Job)error {// Write the job handler logic}

System Components

Life of a schedule

Directory structure

Here's a brief overview of the project's directory structure:

  • cmd/: Contains the main entry points for the scheduler, coordinator, task queue and worker services.
  • pkg/: Contains the core logic for the scheduler, coordinator, task queue and worker services.
  • data/: Contains SQL scripts to initialize the db.
  • tests/: Contains integration tests.
  • *-dockerfile: Dockerfiles for building the scheduler, coordinator, task queue and worker services.
  • docker-compose.yml: Docker Compose configuration file for spinning up the entire cluster.

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp