Go based task runner

Related tags

Job Scheduler grift
Overview

Grift

Grift is a very simple library that allows you to write simple "task" scripts in Go and run them by name without having to write big main type of wrappers. Grift is similar to, and inspired by, Rake.

Why?

Excellent question! When building applications there comes a point where you need different scripts to do different things. For example, you might want a script to seed your database, or perhaps a script to parse some logs, etc...

Grift lets you write these scripts using Go in a really simple and extensible way.

Installation

Installation is really easy using go get.

$ go get github.com/markbates/grift

You can confirm the installation by running:

$ grift jim

Usage/Getting Started

Apart from having the binary installed, the only other requirement is that the package you place your grifts in is called grifts. That's it.

By running the following command:

$ grift init

When you run the init sub-command Grift will generate a new grifts package and create a couple of simple grifts for you.

List available grifts

$ grift list

Say Hello!

$ grift hello

That's it!

That's really it! Grift is meant to be simple. Write your grifts, use the full power of Go to do it.

For more information I would highly recommend checking out the docs.

Examples:

package grifts

import (
	"errors"
	"fmt"
	"os"
	"strings"

	. "github.com/markbates/grift/grift"
)

var _ = Add("boom", func(c *Context) error {
	return errors.New("boom!!!")
})

var _ = Add("hello", func(c *Context) error {
	fmt.Println("Hello World!")
	return nil
})

var _ = Add("hello", func(c *Context) error {
	fmt.Println("Hello World! Again")
	err := Run("db:migrate", c)
	if err != nil {
		return err
	}
	dir, err := os.Getwd()
	if err != nil {
		return err
	}
	fmt.Printf("### dir -> %+v\n", dir)
	return nil
})

var _ = Add("env:print", func(c *Context) error {
	if len(c.Args) >= 1 {
		for _, e := range c.Args {
			fmt.Printf("%s=%s\n", e, os.Getenv(e))
		}
	} else {
		for _, e := range os.Environ() {
			pair := strings.Split(e, "=")
			fmt.Printf("%s=%s\n", pair[0], os.Getenv(pair[0]))
		}
	}

	return nil
})

var _ = Namespace("db", func() {
    Desc("migrate", "Migrates the databases")
    Set("migrate", func(c *Context) error {
            fmt.Println("db:migrate")
            fmt.Printf("### args -> %+v\n", c.Args)
            return nil
    })
}
Issues
  • grift fails to find

    grift fails to find "grifts"-directory

    Error

    Running

    # version 0..4.0
    grift
    

    in directory, results in error message:

    There is no directory named 'grifts'. Run 'grift init' or switch to the appropriate directory
    
    $ pwd
    # => ~/tmp/blub.2.2
    

    Expected result

    The grift is found and run also in projects which are not in GOPATH.

    More information

    I use grift in non-go-projects. With version 0.4.0 this is not possible anymore.

    opened by maxmeyer 4
  • Make grifts more rake-like

    Make grifts more rake-like

    This change adds the concept of namespaces, which work similar to the way rake uses them. This is mostly syntactic sugar around prefixing every task with a common string.

    Instead of:

    var _ = Add("db:migrate", func(c *Context) error{
        return nil
    })
    
    var _ = Add("db:backup", func(c *Context) error{
        return nil
    })
    

    You can now simplify that:

    var _ = Namespace("db", func(){
        Add("migrate", func(c *Context) error{
            return nil
        })
    
        Add("backup", func(c *Context) error{
            return nil
        })
    })
    

    All grift functions within the namespace are affected by the scope of the namespace.

    I've also modified the list command to make it look and behave more like the output of rake -T. This now ignores tasks without descriptions and aligns the descriptions when they are present.

    $ grift list
    grift env:print    # Prints out all of the ENV variables in your environment. Pass in the name of a particular ENV variable to print just that one out. (e.g. grift env:print GOPATH)
    
    $ grift list -a
    grift env:print         # Prints out all of the ENV variables in your environment. Pass in the name of a particular ENV variable to print just that one out. (e.g. grift env:print GOPATH)
    grift foo:hellothing    # 
    grift hello             # 
    
    
    opened by ryanfaerman 3
  • grifter/main.go:4:8 cannot find package

    grifter/main.go:4:8 cannot find package

    I tried to integrate grift to my buffalo project.

    After installing grift by go get github.com/markbates/grift

    Still it's showing me -bash: grift: command not found . I have created GOPATH correctly. buffalo command is working fine.

    And also if I run grift inside my buffalo project, it shows me this error.

    .grifter/main.go:4:8: cannot find package "Users/dilumnavanjana/Documents/Singapore/big-api/grifts" in any of:
    	/usr/local/go/src/Users/dilumnavanjana/Documents/project (from $GOROOT)
    	/Users/dilumnavanjana/go/src/Users/dilumnavanjana/Documents/project/grifts (from $GOPATH)
    

    The GOPATH I configured is /Users/dilumnavanjana/go, here it's showing a wrong GOPATH.

    What is the reason for all these??

    opened by dilumn 3
  • grifter/main.go:4:8: cannot find package

    grifter/main.go:4:8: cannot find package

    grifter/main.go:4:8: cannot find package "fixme_backend/grifts" in any of: /usr/local/Cellar/go/1.11.5/libexec/src/fixme_backend/grifts (from $GOROOT) /Users/biboswanroy/Go/src/fixme_backend/grifts (from $GOPATH)

    Current directory: /Users/biboswanroy/Go/src/github.com/ossn/fixme_backend/ GOPATH=/Users/biboswanroy/Go I have grift command working.

    I see same issue before as well but it didn't help me.

    opened by Biboswan 2
  • Add support for sqlite build tag required by Buffalo.

    Add support for sqlite build tag required by Buffalo.

    Tested OK on Windows using SQLite in Buffalo. I found that fixing it in the Run command worked for both the list case and the run case and it wasn't necessary to change the list() method (it doesn't look like that one is referenced).

    opened by turnkey-commerce 2
  • flag issue

    flag issue

    hi,

    ive encounter issue when i tried to run and pass in parameter with - numbers. where by -1 is the limit of records to unlimited. it does works if we dont use any - hypen. example:

    grift mytask -1
    

    and also grift does not support flags like --limit or -limit right?

    thanks

    opened by u007 2
  • Running Grift outside the GOPATH fails

    Running Grift outside the GOPATH fails

    When running grift with a modules app outside the GOPATH it fails saying:

    build github.com/paganotoni/myapp/.grifter: cannot find module for path myapp/grifts
    

    Result of buffalo info:

    buffalo info
    ### Buffalo Version
    v0.13.2
    
    ### App Information
    Pwd=/Users/paganotoni/code/myapp
    Root=/Users/paganotoni/code/myapp
    GoPath=/Users/paganotoni/go
    Name=myapp
    Bin=bin/myapp
    PackagePkg=../../code/myapp
    ActionsPkg=../../code/myapp/actions
    ModelsPkg=../../code/myapp/models
    GriftsPkg=../../code/myapp/grifts
    VCS=git
    WithPop=true
    WithSQLite=false
    WithDep=false
    WithWebpack=true
    WithYarn=false
    WithDocker=true
    WithGrifts=true
    WithModules=false
    
    ### Go Version
    go version go1.11.1 darwin/amd64
    
    ### Go Env
    GOARCH="amd64"
    GOBIN=""
    GOCACHE="/Users/paganotoni/Library/Caches/go-build"
    GOEXE=""
    GOFLAGS=""
    GOHOSTARCH="amd64"
    GOHOSTOS="darwin"
    GOOS="darwin"
    GOPATH="/Users/paganotoni/go"
    GOPROXY=""
    GORACE=""
    GOROOT="/usr/local/Cellar/go/1.11.1/libexec"
    GOTMPDIR=""
    GOTOOLDIR="/usr/local/Cellar/go/1.11.1/libexec/pkg/tool/darwin_amd64"
    GCCGO="gccgo"
    CC="clang"
    CXX="clang++"
    CGO_ENABLED="1"
    GOMOD="/Users/paganotoni/code/myapp/go.mod"
    CGO_CFLAGS="-g -O2"
    CGO_CPPFLAGS=""
    CGO_CXXFLAGS="-g -O2"
    CGO_FFLAGS="-g -O2"
    CGO_LDFLAGS="-g -O2"
    PKG_CONFIG="pkg-config"
    GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/zx/9gj414m52nj3l_zrlr6903sm0000gn/T/go-build325846444=/tmp/go-build -gno-record-gcc-switches -fno-common"
    
    ### Node Version
    v11.0.0
    
    ### NPM Version
    6.4.1
    
    ### Yarn Version
    1.12.1
    
    ### PostgreSQL Version
    pg_ctl (PostgreSQL) 9.6.10
    
    ### MySQL Version
    MySQL Not Found
    
    ### SQLite Version
    3.24.0 2018-06-04 14:10:15 95fbac39baaab1c3a84fdfc82ccb7f42398b2e92f18a2a57bce1d4a713cbaapl
    
    ### Dep Version
    could not find a Gopkg.toml file
    
    ### Dep Status
    could not find a Gopkg.toml file
    
    ### go.mod
    module github.com/paganotoni/myapp
    
    require (
            github.com/Masterminds/sprig v2.16.0+incompatible // indirect
            github.com/aokoli/goutils v1.0.1 // indirect
            github.com/badoux/checkmail v0.0.0-20180430153108-0755fe2dc241
            github.com/bsphere/le_go v0.0.0-20170215134836-7a984a84b549
            github.com/corpix/uarand v0.0.0-20170903190822-2b8494104d86 // indirect
            github.com/dustin/go-humanize v1.0.0
            github.com/fatih/structs v1.1.0
            github.com/go-playground/form v3.1.3+incompatible
            github.com/gobuffalo/buffalo v0.13.2
            github.com/gobuffalo/buffalo-pop v1.1.8
            github.com/gobuffalo/envy v1.6.7
            github.com/gobuffalo/mw-csrf v0.0.0-20180802151833-446ff26e108b
            github.com/gobuffalo/mw-i18n v0.0.0-20181027200759-09e0c99be4d3
            github.com/gobuffalo/mw-paramlogger v0.0.0-20181005191442-d6ee392ec72e
            github.com/gobuffalo/packr v1.16.0
            github.com/gobuffalo/plush v3.7.21+incompatible
            github.com/gobuffalo/pop v4.8.7+incompatible
            github.com/gobuffalo/suite v2.2.0+incompatible
            github.com/gobuffalo/tags v2.0.11+incompatible
            github.com/gobuffalo/uuid v2.0.5+incompatible
            github.com/gobuffalo/validate v2.0.3+incompatible
            github.com/google/uuid v1.0.0 // indirect
            github.com/huandu/xstrings v1.2.0 // indirect
            github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428
            github.com/imdario/mergo v0.3.6 // indirect
            github.com/jaytaylor/html2text v0.0.0-20180606194806-57d518f124b0 // indirect
            github.com/leekchan/accounting v0.0.0-20180703100437-18a1925d6514
            github.com/markbates/going v1.0.2
            github.com/markbates/grift v1.0.5
            github.com/markbates/inflect v1.0.4
            github.com/matcornic/hermes v1.2.0
            github.com/mattn/go-runewidth v0.0.3 // indirect
            github.com/monoculum/formam v0.0.0-20180901015400-4e68be1d79ba
            github.com/newrelic/go-agent v2.1.0+incompatible
            github.com/olekukonko/tablewriter v0.0.1 // indirect
            github.com/pkg/errors v0.8.0
            github.com/sendgrid/rest v2.4.1+incompatible // indirect
            github.com/sendgrid/sendgrid-go v3.4.1+incompatible
            github.com/sirupsen/logrus v1.1.1
            github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
            github.com/stanislas-m/mocksmtp v1.0.0
            github.com/stretchr/testify v1.2.2
            golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16
            gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
    )
    
    opened by paganotoni 1
  • build fails in go module

    build fails in go module

    Steps to reproduce:

    mkdir testgrift && cd "$_"  #(outside of $GOPATH)
    git init
    git remote add origin [email protected]:rrrkren/testgrift.git
    go mod init
    grift init
    grift hello
    

    gives error:

    build github.com/rrrkren/testgrift/.grifter: cannot find module for path testgrift/grifts
    exit status 1
    

    when I do this process without the git part everything work fine

    opened by rrrkren 1
  • Add support for sqlite build tag for config/database.yml

    Add support for sqlite build tag for config/database.yml

    Hi Mark

    I'm using pop and grift in a small project (without buffalo) using sqlite.

    When i use grift to run a command that uses sqlite, i get the error...

    sqlite3 was not compiled into the binary
    

    I see Grift PR #23 you provided a fix for the case when database.yml is in the root directory.

    In the Pop docs it says database.yml can live in the root or in a config folder.

    Pop is easily configured using a YAML file. The configuration file 
    should be stored in config/database.yml or database.yml.
    

    For those people that have their database.yml in the config folder, this PR fixes the issue.

    Feel free to implement it better :) The idea is just to check in both locations for the database.yml file.

    Regards, Gareth

    opened by g4z 1
  • calling grift hello causes sql: Register called twice for driver postgres

    calling grift hello causes sql: Register called twice for driver postgres

    hi

    i tried run in coke new project, and it works. but for my project, none task works

    $ grift hello
    panic: sql: Register called twice for driver postgres
    
    goroutine 1 [running]:
    database/sql.Register(0x4cae8a4, 0x8, 0x5360080, 0x53e6700)
    	/usr/local/Cellar/go/1.9.3/libexec/src/database/sql/sql.go:50 +0x1ad
    project/vendor/github.com/lib/pq.init.0()
    	/Users/james/www/gowork/src/project/vendor/github.com/lib/pq/conn.go:49 +0x60
    project/vendor/github.com/lib/pq.init()
    	<autogenerated>:1 +0x782
    project/vendor/github.com/markbates/pop.init()
    	<autogenerated>:1 +0x8c
    project/db.init()
    	<autogenerated>:1 +0x49
    project/grifts.init()
    	<autogenerated>:1 +0x82
    main.init()
    	<autogenerated>:1 +0x44
    
    
    opened by u007 1
  • Source run

    Source run

    It's a handy utility named after the 'source' bash command that aims to remove lot's of boilerplate code found throughout grift itself and other programs that use grift. If you look at current run.go on the diff or for example at pop/grifts you can spot this pattern.

    I believe that this is the correct place for this, because whenever making grifts/importing grift to the current namespace, it is common to run commands in this manner. :)

    opened by ntakouris 1
  • Run should say something if task doesn't exist

    Run should say something if task doesn't exist

    When using grift.Run inside another grift with a task that doesn't exist Grift doesn't say anything and doesn't do anything, it should at least say that the invoked grift doesn't exist.

    opened by paganotoni 0
  • Context Logger

    Context Logger

    When running periodic tasks in production usually there is a need to follow the details of what the task is doing, it would be great if the grift Context could have a Logger() method (as buffalo does) that returns a logger one could set in the grift init.

    This would allow to add custom loggers and have it handy while the task is running. Another cool addition would be to call c.Logger().Error(err) if the task returns an error.

    opened by paganotoni 0
Releases(v1.5.0)
Owner
Mark Bates
Mark Bates is a full stack web developer with over 18 years of experience building high quality scalable applications for companies.
Mark Bates
Task Timer (tt) is a dead simple TUI task timer

tasktimer Task Timer (tt) is a dead simple TUI task timer Usage To get started, just run tt: tt You'll be presented with something like this: You can

Carlos Alexandro Becker 245 Aug 10, 2022
Gotask - A simple task queue is stripped when the program is written to achieve the task delivery function

gotask The simple task queue is stripped when the program is written to achieve

SaiRson 4 Feb 14, 2022
Go-based runner for Cron Control

Cron Control Runner A Go-based runner for processing WordPress cron events, via Cron Control interfaces. Installation & Usage Clone the repo, and cd i

Automattic 8 Jul 19, 2022
Machinery is an asynchronous task queue/job queue based on distributed message passing.

Machinery Machinery is an asynchronous task queue/job queue based on distributed message passing. V2 Experiment First Steps Configuration Lock Broker

Richard Knop 6.4k Aug 12, 2022
Distributed Task Scheduling System|分布式定时任务调度平台

Crocodile Distributed Task Scheduling System English | 中文 Introduction A distributed task scheduling system based on Golang that supports http request

labulaka521 862 Aug 2, 2022
go task pool

Task Pool Task Pool 是一个易于使用且高度可配置的 golang类库,专门用于任务的管理&执行,支持自定义次数的重发。 功能特点 线程安全 - task pool 内所有的方法以及暴露的接口都是线程安全的 异步发送 - 调用 PushTask 方法后回立即返回,任务将会被传递到io

qinhan 30 Feb 21, 2022
Celery Distributed Task Queue in Go

gocelery Go Client/Server for Celery Distributed Task Queue Why? Having been involved in several projects migrating servers from Python to Go, I have

gocelery 2k Aug 11, 2022
high performance distributed task scheduling system, Support multi protocol scheduling tasks

high performance distributed task scheduling system, Support multi protocol scheduling tasks

null 58 Aug 4, 2022
Chrono is a scheduler library that lets you run your task and code periodically

Chrono is a scheduler library that lets you run your tasks and code periodically. It provides different scheduling functionalities to make it easier t

Procyon 192 Aug 8, 2022
YTask is an asynchronous task queue for handling distributed jobs in golang

YTask is an asynchronous task queue for handling distributed jobs in golang

gojuukaze 202 Jul 15, 2022
goInterLock is golang job/task scheduler with distributed locking mechanism (by Using Redis🔒).

goInterLock is golang job/task scheduler with distributed locking mechanism. In distributed system locking is preventing task been executed in every instant that has the scheduler,

Jay Ehsaniara 23 Jul 18, 2022
go-sche is a golang library that lets you schedule your task to be executed later.

go-sche is a golang library that lets you schedule your task to be executed later.

cza 2 Jul 4, 2022
Go distributed task scheduler

Go distributed task scheduler

Nuggets 1 Nov 13, 2021
Tasks - Golang CLI, Task manager

Tasks Golang CLI, Task manager Prerequisites Golang Setup environment variables

Santiago Bedoya 0 Jan 30, 2022
A lightweight job scheduler based on priority queue with timeout, retry, replica, context cancellation and easy semantics for job chaining. Build for golang web apps.

Table of Contents Introduction What is RIO? Concern An asynchronous job processor Easy management of these goroutines and chaining them Introduction W

Supratim Samanta 49 May 3, 2022
Crane scheduler is a Kubernetes scheduler which can schedule pod based on actual node load.

Crane-scheduler Overview Crane-scheduler is a collection of scheduler plugins based on scheduler framework, including: Dynamic scheuler: a load-aware

Crane 58 Aug 10, 2022
ezd is an easy to configure docker-based task runner system

ezd - eZ Docker Task Runner ezd is an easy to configure docker-based task runner system. Getting started Create an ezd.yml file in your project root:

Daniel Christian Kupczak 4 Feb 11, 2022
Realize is the #1 Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading.

#1 Golang live reload and task runner Content - ⭐️ Top Features - ???? Get started - ?? Config sample - ?? Commands List - ?? Support and Suggestions

Oxequa 4.3k Aug 11, 2022
Concurrent task runner, developer's routine tasks automation toolkit. Simple modern alternative to GNU Make 🧰

taskctl - concurrent task runner, developer's routine tasks automation toolkit Simple modern alternative to GNU Make. taskctl is concurrent task runne

null 204 Aug 11, 2022
Build system and task runner for Go projects

Gilbert is task runner that aims to provide declarative way to define and run tasks like in other projects like Gradle, Maven and etc.

Gilbert 101 Aug 8, 2022
Realize is the #1 Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading.

#1 Golang live reload and task runner Content - ⭐️ Top Features - ???? Get started - ?? Config sample - ?? Commands List - ?? Support and Suggestions

Oxequa 4.3k Aug 15, 2022
A task runner / simpler Make alternative written in Go

Task Task is a task runner / build tool that aims to be simpler and easier to use than, for example, GNU Make. See taskfile.dev for the documentation.

Task 5.6k Aug 18, 2022
Act is a task runner and supervisor with some great features like act name matching, subacts, etc. We use this in nosebit workspaces.

Act Act is a task runner and supervisor tool written in Go which aims to provide the following features: process supervision in a project level allow

Nosebit 6 May 8, 2022
A cross-platform task runner for executing commands and generating files from templates

Orbit A cross-platform task runner for executing commands and generating files from templates Orbit started with the need to find a cross-platform alt

Julien Neuhart 169 Aug 6, 2022
Job queuing service and async task runner.

Valet Stateless Go server responsible for running tasks asynchronously and concurrently. Overview Job Pipeline Architecture Installation Configuration

Stefanos Valoumas 23 Jun 23, 2022
tasq is a simple HTTP-based task queue. Each task is represented as a string

tasq tasq is a simple HTTP-based task queue. Each task is represented as a string (it could be anything). Tasks are pushed to the queue via an HTTP en

Alex Nichol 5 May 26, 2022
Task Timer (tt) is a dead simple TUI task timer

tasktimer Task Timer (tt) is a dead simple TUI task timer Usage To get started, just run tt: tt You'll be presented with something like this: You can

Carlos Alexandro Becker 245 Aug 10, 2022
GTA(Go Task Async) is a lightweight reliable asynchronous task and transaction message library for Golang

GTA (Go Task Async) is a lightweight and reliable asynchronous task and transaction message library for by golang.

Kevin Su 12 Jun 4, 2022
Gotask - A simple task queue is stripped when the program is written to achieve the task delivery function

gotask The simple task queue is stripped when the program is written to achieve

SaiRson 4 Feb 14, 2022