crontab-go

command module
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: GPL-2.0 Imports: 10 Imported by: 0

README

Cronjob-go

Keep a Changelog GitHub Release Go Reference go.mod LICENSE Go Report Card Codecov

Star this repository if you find it valuable and worth maintaining.

👁 Watch this repository to get notified about new releases, issues, etc.

Description

Cronjob-go: A Robust Cron Scheduler for Docker Environments

Cronjob-go is a powerful, lightweight, and highly configurable Golang application designed to replace the traditional crontab in Docker environments. With its seamless integration and easy-to-use YAML configuration, Cronjob-go simplifies the process of scheduling and managing recurring tasks within your containerized applications.

Key Features

  1. YAML Configuration: Cronjob-go leverages YAML for its configuration, making it easy to define and manage your scheduled tasks. The YAML format provides a clean and human-readable way to specify task details, schedules, and other settings.

  2. Robust Scheduling: The application uses a reliable and flexible scheduling engine to ensure that your tasks are executed on time. It supports a wide range of scheduling patterns, including cron-style expressions, intervals, and custom scheduling logic.

  3. Container-Friendly: Cronjob-go is designed with Containerization in mind, making it the perfect replacement for crontab in your containerized environments.

  4. Logging and Monitoring: The application provides comprehensive logging and monitoring capabilities, allowing you to track the execution of your scheduled tasks and quickly identify and resolve any issues that may arise.

Use Cases:

  • Automated Backups: Schedule regular backups of your application data or logs to ensure data integrity and disaster recovery.
  • Periodic Maintenance Tasks: Execute maintenance tasks, such as database optimizations, cache clearance, or system updates, on a scheduled basis.
  • Data Processing and Reporting: Automate the processing and generation of reports, analytics, or other data-driven tasks.

Configuration

This section outlines the configuration options available for the application.

Environment Variables:

  • All environment variables and configuration samples are provided in .env.example and config.example.yaml files.

Logging:

  • Time Format: The default timestamp format is 2006-01-02T15:04:05.000Z (Golang's datetime format). You can customize this format using the LOG_TIMESTAMP_FORMAT environment variable.
  • Log Format: The default log format is ansi (colorful). You can choose from ansi (colorful), plain (no colors), and json using the LOG_FORMAT environment variable.
  • Log File: Logs can be saved to a file by setting the LOG_FILE environment variable.
  • StdOut: Outputting logs to standard output can be disabled by setting LOG_STDOUT=false.
  • Log Level: The default log level is info. You can adjust the level from most verbose to least verbose: trace, debug, info, warn, fatal, panic using the LOG_LEVEL environment variable.

Shell:

  • Shell: The application leverages your system's shell to execute commands. The default shell is sh for Linux and cmd for Windows. You can override the default using the SHELL environment variable, which can be set individually for each process.
  • Shell Args: The default shell arguments are -c for sh (Linux) and /c for cmd (Windows). These can be customized using the SHELL_ARGS environment variable.

Configuration File:

  • A fully documented configuration file is available at config.example.yaml.
  • You can select config file using --config (-c) flag. crontab-go -c config.example.yaml
  • You can also use schema.json as schema of config file.

By adding this line in the config.yaml file you can enable the schema.

# yaml-language-server: $schema=https://github.com/FMotalleb/crontab-go/raw/main/schema.json

Getting Started

To get started with Cronjob-go, simply download the binary for your platform and configure your scheduled tasks using the provided YAML format. The application's documentation includes detailed instructions on installation, configuration, and usage, making it easy to integrate into your existing Docker-based infrastructure.

Thanks To

This project was possible thanks to

  • Logrus
    • Logrus is a structured logger for Go (golang), completely API compatible with the standard library logger.
  • Cobra
    • Cobra is a library for creating powerful modern CLI applications.
  • Viper
    • Go configuration with fangs!
  • Cron
    • Cron backend!
  • GoDotenv
    • A Go (golang) port of the Ruby dotenv project (which loads env vars from a .env file).

Documentation

Overview

Copyright © 2024 Motalleb Fallahnezhad

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Directories

Path Synopsis
Package abstraction must contain only interfaces and abstract layers of modules
Package abstraction must contain only interfaces and abstract layers of modules
cmd
Package cmd manages the command line interface/configuration file handling logic
Package cmd manages the command line interface/configuration file handling logic
parser
Package parser manages holds the logic behind the sub command `parse` this package is responsible for parsing a crontab file into valid config yaml file
Package parser manages holds the logic behind the sub command `parse` this package is responsible for parsing a crontab file into valid config yaml file
Package config contains the configuration information of the application.
Package config contains the configuration information of the application.
compiler
Package cfgcompiler provides mapper functions for the config structs
Package cfgcompiler provides mapper functions for the config structs
core
cmd_connection
Package connection provides implementation of the abstraction.CmdConnection interface for command tasks.
Package connection provides implementation of the abstraction.CmdConnection interface for command tasks.
common
Package common provides implementation of some of the basic functionalities to be used in application.
Package common provides implementation of some of the basic functionalities to be used in application.
concurrency
Package concurrency provides utility functions for working with goroutines.
Package concurrency provides utility functions for working with goroutines.
event
Package event contains all event emitters supported by this package.
Package event contains all event emitters supported by this package.
global
Package global contains global state management logics
Package global contains global state management logics
jobs
Package jobs implements the main functionality for the jobs in the application
Package jobs implements the main functionality for the jobs in the application
os_credential
Package credential provides functions to switch group and user for command execution.
Package credential provides functions to switch group and user for command execution.
task
Package task provides implementation of the abstraction.Executable interface for command tasks.
Package task provides implementation of the abstraction.Executable interface for command tasks.
utils
Package utils provides utility functions.
Package utils provides utility functions.
webserver
Package webserver implements the logic for the webserver
Package webserver implements the logic for the webserver
webserver/endpoint
Package endpoint implements the logic behind each endpoint of the webserver
Package endpoint implements the logic behind each endpoint of the webserver
Package ctxutils provides utility functions for working with context.Context.
Package ctxutils provides utility functions for working with context.Context.
Package enums provides enums used in crontab-go.
Package enums provides enums used in crontab-go.
Package helpers provides helper functions.
Package helpers provides helper functions.
Package logger contains basic logging logic of the application
Package logger contains basic logging logic of the application
mock_logger
Package mocklogger provides a logrus.Logger that does not log into stdout or stderr.
Package mocklogger provides a logrus.Logger that does not log into stdout or stderr.
Package meta contains meta data information about this program.
Package meta contains meta data information about this program.

Jump to

Keyboard shortcuts

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