This repository has been archived by the owner on Apr 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
Add cron recipe to allow per-app scheduled tasks. #160
Open
berkes
wants to merge
7
commits into
intercity:master
Choose a base branch
from
berkes:feature/cron
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b690656
Add boilerplate for new cron cookbook.
berkes 5534dfd
Add recipe to create per-app crontab entries.
berkes 57edd53
Add cron recipe to repo Cheffile.
berkes 65d2bb9
Add a crontab example to VagrantFile for debugging.
berkes 245cd5f
Implement HoundCI suggestions.
berkes 6885e91
Typofix in the documentation: leftover copy-paste errorf from sysadmins.
berkes 5a50273
Add an example crontab entry to the sample_host
berkes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
See https://github.com/intercity/chef-repo/blob/master/CHANGELOG.md for full | ||
changelog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
Cron Cookbook | ||
================== | ||
|
||
Schedules tasks for apps. It simply adds entries to the root crontab | ||
with commands that will be ran within the context of the app. | ||
|
||
Attributes | ||
---------- | ||
|
||
#### sysadmins::default | ||
<table> | ||
<tr> | ||
<th>Key</th> | ||
<th>Type</th> | ||
<th>Description</th> | ||
<th>Default</th> | ||
</tr> | ||
<tr> | ||
<td><tt>['cron']></td> | ||
<td>Hash</td> | ||
<td>key: identifier</td> | ||
<td><tt>empty, won't schedule tasks.</tt></td> | ||
</tr> | ||
</table> | ||
|
||
Usage | ||
----- | ||
|
||
Add cron to your node configuration: | ||
|
||
```@json | ||
{ | ||
"cron": { | ||
"sitemap": { | ||
"minute": 0, | ||
"hour": 5, | ||
"command": "rake -s sitemap:refresh" | ||
} | ||
} | ||
``` | ||
This runs the command `..... bundle exec rake -s sitemap:refresh` every | ||
day at 5:00. | ||
|
||
See the full list of available attributes at [the cron resource | ||
documentation](http://docs.chef.io/resource_cron.html). | ||
|
||
All attributes will be passed literarally from the node configuration | ||
into the cron resource. With a few exceptions: | ||
|
||
* Command will be prefixed with code so it runs within the app current dir. | ||
* User defaults to the deploy\_user for the app ("deploy"). Be carefull when overriding. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name "cron" | ||
maintainer "Bèr `berkes` Kessels" | ||
maintainer_email "[email protected]" | ||
license "MIT" | ||
description "Schedules tasks for apps" | ||
long_description IO.read(File.join(File.dirname(__FILE__), "README.md")) | ||
version "0.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# | ||
# Cookbook Name:: cron | ||
# Recipe:: default | ||
# | ||
# Copyright 2014, Bèr `berkes` Kessels | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
|
||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
|
||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
|
||
return unless node[:active_applications] | ||
|
||
node[:active_applications].map do |app, app_info| | ||
app_info["cron"].each do |id, crontab| | ||
attributes = crontab.dup | ||
|
||
unscoped_command = attributes.delete("command") | ||
rails_env = app_info['rails_env'] || "production" | ||
user = attributes.delete("user") || app_info['deploy_user'] || "deploy" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
app_dir = "#{node[:rails][:applications_root]}/#{app}/current" | ||
|
||
command = "cd #{app_dir} && ( PATH=/opt/rbenv/shims:$PATH RAILS_ENV=#{rails_env} bundle exec #{unscoped_command} )" | ||
|
||
cron "#{app}_#{id}" do | ||
command(command) | ||
user(user) | ||
attributes.each {|attribute, value| send(attribute, value) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space between { and | missing. |
||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.