go-task

command module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 2 Imported by: 0

README

go-task

gtask can manage scheduled and worker tasks.

Config file

workers:
  - id: "task1"
    command: "echo 'task 1'"
  - id: "task2"
    command: "echo 'task 2'"

scheduled:
  - id: "task1"
    expr: "*/5 * * * *"
    command: "echo 'task 1'"
  - id: "task2"
    expr: "0 12 * * *"
    command: "echo 'task 2'"

Usage

Usage:
  gtask [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command
  schedule    schedule sub commands
  validate    validate config
  version     Show version info
  worker      worker sub commands

Workers
Generate Supervisord config

CLI options:

  • user: Define user who run command
  • working-dir: Define working dir
  • group-name: Define group name (like prefix)
  • output: Define path to save config file
  • format: Choose format of output file
# this command will read gtask.yml and generate supervisord config with workers list.
gtask worker generate --config gtask.yml --group-name my-group --format supervisor --output dest/path.conf
Extra params for supervisord

You can pass additional supervisord directives per worker using template.extra_params. These are injected into the [program:xxx] section of the generated config.

workers:
  - id: "task1"
    command: "echo 'task 1'"
    template:
      extra_params:
        program:
          stopasgroup: "true"
          killasgroup: "true"
  - id: "task2"
    command: "echo 'task 2'"

This will generate:

[program:my-group-task1]
directory = /app
autorestart = true
autostart = true
user = www-data
command = echo 'task 1'
environment = ...
stopasgroup = true
killasgroup = true

[program:my-group-task2]
directory = /app
autorestart = true
autostart = true
user = www-data
command = echo 'task 2'
environment = ...
Multiple instances

Use the instances field to run multiple copies of a worker. Each instance gets a unique name with a _N suffix. When instances is 1 (default), no suffix is added.

workers:
  - id: "task1"
    command: "echo 'task 1'"
    instances: 3

This will generate 3 programs: my-group-task1_1, my-group-task1_2, my-group-task1_3.

Each instance exposes two environment variables:

  • GTASK_ID: the parent worker ID (my-group-task1)
  • GTASK_INSTANCE_ID: the unique instance ID (my-group-task1_1, my-group-task1_2, etc.)
schedule
Run

CLI options:

  • working-dir: Define working dir
  • timezone: Choose a specific timezone
  • no-result-print: Hide output of command
  • result-path: Define path to save output of command
# this command will read gtask.yml and run scheduled tasks (based on cron expr). 
gtask schedule run --config gtask.yml
# or 
gtask schedule run --config gtask.yml --timezone 'Europe/Paris'
Start

CLI options:

  • working-dir: Define working dir
  • timezone: Choose a specific timezone
  • no-result-print: Hide output of command
  • result-path: Define path to save output of command
  • tick: Select duration of each tick
# this command will read gtask.yml and start a daemon that scheduled tasks (based on cron expr). 
gtask schedule start --config gtask.yml
# or 
gtask schedule start --config gtask.yml --timezone 'Europe/Paris' --tick 10m

Requirements

  • golang (1.21+)

Development

  • Install dependencies:

    go mod download
    
  • Generate mocks:

    ./bin/mock.sh
    
  • Build the project:

    go build .
    
  • Run tests:

    go test ./...
    

License

MIT License, see LICENSE.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL