Awesome Open Source
Awesome Open Source

💤 sleepto

GoDoc Build Status Go Report Card

sleepto is a simple alternative to task schedulers like Cron.

It only handles the timing and doesn't run a daemon like other schedulers do. Instead we encourage you to use your systems default init system (for example Systemd) to control your jobs. This allows you to:

  • Use and watch scheduled jobs the way you use all other services running on your system (for example using ps).
  • Start and pause jobs like any other service on your system.
  • Use your systems default logging system.
  • No conflicts - next task is only scheduled after previous one finished.
  • Trigger immediate execution by sending a SIGALRM signal.
  • Specify execution times with the precision of seconds (Cron only supports minutes).
  • Always know the time of the next execution.

Thanks to runwhen for inspiration.

Usage: sleepto [flags...] [command...]

Sleep until next time the specified conditions match.

Conditions are specified with flags.
All flags are optional and can be used in any combination.
The condition flags take one or more value each.
Values are separated by comma.

Note that conditions match not the current, but the next possible match.
When the current date is March 2017
and you run 'sleepto -month 3' the execution time is March 1, 2018.

A command can be specified optionally.
All arguments following the command are passed to it.

When the process receives a SIGALRM signal it finishes immediately.

Examples:
  # Next 10th of month at 3pm
  sleepto -day 10 -hour 15 /bin/send-report
  # Next occurence of one quarter of hour
  sleepto -minute 0,15,30,45 say "Hello human"
  # Next day at 1am
  sleepto -hour 1 && ~/dbbackup.sh

Flags:
  -day value
        1 to 31
  -hour value
        0 to 23
  -minute value
        0 to 59
  -month value
        1 to 12
  -second value
        0 to 59
  -silent
        Suppress all output
  -version
        Print binary version
  -weekday value
        mo,tu,we,th,fr,sa,su
  -year value
        list of years

For more visit: https://qvl.io/sleepto

Install

  • With Go:
go get qvl.io/sleepto
brew install qvl/tap/sleepto

Setup

sleepto can be used in different scenarios but the most common one is probably to combine it with an init system.

Systemd

Systemd already runs on most Linux systems.

It even has its own timer implementation which can be the right solution for many use cases. However, if you don't want to depend on the specific features of one init system or you like to reuse the same logic in other scenarios sleepto can be the the right tool for that.

See ghbackup for an example on how to use sleepto in a service.

  • See the logs for your service use:
sudo journalctl -u servicename
  • List processes which should include your service:
ps fux
  • Immediately finish sleeping:
sudo systemctl kill -s ALRM servicename

Development

Make sure to use gofmt and create a Pull Request.

Releasing

Push a new Git tag and GoReleaser will automatically create a release.

License

MIT


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
go (14,405) 
golang (3,668) 
cron (113) 
schedule (69) 
systemd (51) 
job-scheduler (40) 
task-scheduler (30) 

Find Open Source By Browsing 7,000 Topics Across 59 Categories

Advertising 📦 10
All Projects
Application Programming Interfaces 📦 124
Applications 📦 192
Artificial Intelligence 📦 78
Blockchain 📦 73
Build Tools 📦 113
Cloud Computing 📦 80
Code Quality 📦 28
Collaboration 📦 32
Command Line Interface 📦 49
Community 📦 83
Companies 📦 60
Compilers 📦 63
Computer Science 📦 80
Configuration Management 📦 42
Content Management 📦 175
Control Flow 📦 213
Data Formats 📦 78
Data Processing 📦 276
Data Storage 📦 135
Economics 📦 64
Frameworks 📦 215
Games 📦 129
Graphics 📦 110
Hardware 📦 152
Integrated Development Environments 📦 49
Learning Resources 📦 166
Legal 📦 29
Libraries 📦 129
Lists Of Projects 📦 22
Machine Learning 📦 347
Mapping 📦 64
Marketing 📦 15
Mathematics 📦 55
Media 📦 239
Messaging 📦 98
Networking 📦 315
Operating Systems 📦 89
Operations 📦 121
Package Managers 📦 55
Programming Languages 📦 245
Runtime Environments 📦 100
Science 📦 42
Security 📦 396
Social Media 📦 27
Software Architecture 📦 72
Software Development 📦 72
Software Performance 📦 58
Software Quality 📦 133
Text Editors 📦 49
Text Processing 📦 136
User Interface 📦 330
User Interface Components 📦 514
Version Control 📦 30
Virtualization 📦 71
Web Browsers 📦 42
Web Servers 📦 26
Web User Interface 📦 210