poise-application-python 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.kitchen.travis.yml +9 -0
- data/.kitchen.yml +10 -0
- data/.travis.yml +20 -0
- data/.yardopts +3 -0
- data/Berksfile +35 -0
- data/CHANGELOG.md +71 -0
- data/Gemfile +37 -0
- data/LICENSE +201 -0
- data/README.md +334 -0
- data/Rakefile +17 -0
- data/SUPPORTERS.md +81 -0
- data/chef/templates/celeryconfig.py.erb +5 -0
- data/chef/templates/settings.py.erb +13 -0
- data/lib/poise_application_python.rb +23 -0
- data/lib/poise_application_python/app_mixin.rb +67 -0
- data/lib/poise_application_python/cheftie.rb +17 -0
- data/lib/poise_application_python/error.rb +25 -0
- data/lib/poise_application_python/resources.rb +26 -0
- data/lib/poise_application_python/resources/celery_beat.rb +43 -0
- data/lib/poise_application_python/resources/celery_config.rb +109 -0
- data/lib/poise_application_python/resources/celery_worker.rb +77 -0
- data/lib/poise_application_python/resources/django.rb +355 -0
- data/lib/poise_application_python/resources/gunicorn.rb +127 -0
- data/lib/poise_application_python/resources/pip_requirements.rb +47 -0
- data/lib/poise_application_python/resources/python.rb +57 -0
- data/lib/poise_application_python/resources/python_execute.rb +89 -0
- data/lib/poise_application_python/resources/python_package.rb +62 -0
- data/lib/poise_application_python/resources/virtualenv.rb +75 -0
- data/lib/poise_application_python/service_mixin.rb +57 -0
- data/lib/poise_application_python/version.rb +19 -0
- data/poise-application-python.gemspec +45 -0
- data/test/cookbooks/application_python_test/attributes/default.rb +17 -0
- data/test/cookbooks/application_python_test/metadata.rb +20 -0
- data/test/cookbooks/application_python_test/recipes/default.rb +83 -0
- data/test/cookbooks/application_python_test/recipes/django.rb +32 -0
- data/test/cookbooks/application_python_test/recipes/flask.rb +25 -0
- data/test/gemfiles/chef-12.gemfile +19 -0
- data/test/gemfiles/master.gemfile +27 -0
- data/test/integration/default/serverspec/default_spec.rb +81 -0
- data/test/integration/default/serverspec/django_spec.rb +56 -0
- data/test/integration/default/serverspec/flask_spec.rb +39 -0
- data/test/spec/app_mixin_spec.rb +69 -0
- data/test/spec/resources/celery_config_spec.rb +58 -0
- data/test/spec/resources/django_spec.rb +303 -0
- data/test/spec/resources/gunicorn_spec.rb +96 -0
- data/test/spec/resources/python_execute_spec.rb +46 -0
- data/test/spec/resources/python_spec.rb +44 -0
- data/test/spec/resources/virtualenv_spec.rb +44 -0
- data/test/spec/spec_helper.rb +19 -0
- metadata +216 -0
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'poise_boiler/rakefile'
|
data/SUPPORTERS.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Supporters
|
2
|
+
|
3
|
+
This cookbook wouldn't have been possible without the generous support of my
|
4
|
+
Kickstarter backers. Thanks so much to every one of you!
|
5
|
+
|
6
|
+
* @kcunning
|
7
|
+
* Alberto Lorenzo Pulido
|
8
|
+
* Alex Gaynor
|
9
|
+
* Alexander Myasnikov
|
10
|
+
* Brooke Schreier Ganz
|
11
|
+
* Bryan McLellan
|
12
|
+
* Charles Johnson
|
13
|
+
* Chef Software, Inc.
|
14
|
+
* Chris Adams
|
15
|
+
* Christopher Petrilli
|
16
|
+
* David Thornton
|
17
|
+
* Derek Murawsky
|
18
|
+
* Fast Robot, LLC
|
19
|
+
* Fatty McAwesome Pants (Kate Heddleston)
|
20
|
+
* Greg Albrecht
|
21
|
+
* JD Harrington
|
22
|
+
* Jake Plimack
|
23
|
+
* Jason Cook
|
24
|
+
* Jeff Byrnes
|
25
|
+
* Jeff Forcier
|
26
|
+
* Jeff Lindsay
|
27
|
+
* Jennifer Davis
|
28
|
+
* John Fitch
|
29
|
+
* Jon Stacks
|
30
|
+
* Joshua SS Miller
|
31
|
+
* Julian Dunn
|
32
|
+
* Julien Phalip
|
33
|
+
* Kennon Kwok
|
34
|
+
* Kevin Duane
|
35
|
+
* Krzysztof Wilczynski
|
36
|
+
* Linda Goldstein
|
37
|
+
* Manny Toledo
|
38
|
+
* Marco A Morales
|
39
|
+
* Marcus Morris
|
40
|
+
* Mark Luntzel
|
41
|
+
* Martin B. Smith
|
42
|
+
* Mathieu Sauve-Frankel
|
43
|
+
* Matt Good
|
44
|
+
* Matt Juszczak
|
45
|
+
* Matt Ray
|
46
|
+
* Matt Stratton
|
47
|
+
* Michael Burns
|
48
|
+
* Miguel Landaeta
|
49
|
+
* Mike Schueler
|
50
|
+
* Nathan L Smith
|
51
|
+
* Nathen Harvey
|
52
|
+
* Paul Welch
|
53
|
+
* Peter Kropf
|
54
|
+
* Phil Mocek
|
55
|
+
* Practice Fusion Inc
|
56
|
+
* Ranjib
|
57
|
+
* Richard Jones
|
58
|
+
* Robert J. Berger
|
59
|
+
* Robin Levin
|
60
|
+
* Roland Moriz
|
61
|
+
* Ruben Orduz
|
62
|
+
* Russell Keith-Magee
|
63
|
+
* Ryan Hass
|
64
|
+
* Sam Clements
|
65
|
+
* Sean OMeara
|
66
|
+
* Seva Feldman
|
67
|
+
* Soo Choi
|
68
|
+
* Steven Danna
|
69
|
+
* Symonds & Son
|
70
|
+
* Todd Michael Bushnell
|
71
|
+
* Tracy Osborn
|
72
|
+
* Troy Ready
|
73
|
+
* Tyler Ball
|
74
|
+
* Vicky Tuite
|
75
|
+
* Ying Li
|
76
|
+
* Yvo van Doorn
|
77
|
+
* Zac Stevens
|
78
|
+
* lvh
|
79
|
+
* oolongtea
|
80
|
+
* smeuser
|
81
|
+
* tmonk42
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Generated by Chef for <%= @new_resource.to_s %>
|
2
|
+
|
3
|
+
<%- unless @allowed_hosts.empty? -%>
|
4
|
+
ALLOWED_HOSTS = <%= PoisePython::Utils.to_python(@allowed_hosts) %>
|
5
|
+
|
6
|
+
<%- end -%>
|
7
|
+
DEBUG = <%= PoisePython::Utils.to_python(@debug) %>
|
8
|
+
|
9
|
+
DATABASES = <%= PoisePython::Utils.to_python(@databases) %>
|
10
|
+
<%- if @secret_key -%>
|
11
|
+
|
12
|
+
SECRET_KEY = <%= PoisePython::Utils.to_python(@secret_key) %>
|
13
|
+
<%- end -%>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
|
18
|
+
module PoiseApplicationPython
|
19
|
+
autoload :AppMixin, 'poise_application_python/app_mixin'
|
20
|
+
autoload :Error, 'poise_application_python/error'
|
21
|
+
autoload :Resources, 'poise_application_python/resources'
|
22
|
+
autoload :VERSION, 'poise_application_python/version'
|
23
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'poise/backports'
|
18
|
+
require 'poise/utils'
|
19
|
+
require 'poise_application/app_mixin'
|
20
|
+
require 'poise_python/python_command_mixin'
|
21
|
+
|
22
|
+
|
23
|
+
module PoiseApplicationPython
|
24
|
+
# A helper mixin for Python application resources and providers.
|
25
|
+
#
|
26
|
+
# @since 4.0.0
|
27
|
+
module AppMixin
|
28
|
+
include Poise::Utils::ResourceProviderMixin
|
29
|
+
|
30
|
+
# A helper mixin for Python application resources.
|
31
|
+
module Resource
|
32
|
+
include PoiseApplication::AppMixin::Resource
|
33
|
+
include PoisePython::PythonCommandMixin::Resource
|
34
|
+
|
35
|
+
# @!attribute parent_python
|
36
|
+
# Override the #parent_python from PythonCommandMixin to grok the
|
37
|
+
# application level parent as a default value.
|
38
|
+
# @return [PoisePython::Resources::PythonRuntime::Resource, nil]
|
39
|
+
parent_attribute(:python, type: :python_runtime, optional: true, default: lazy { app_state_python.equal?(self) ? nil : app_state_python })
|
40
|
+
|
41
|
+
# @attribute app_state_python
|
42
|
+
# The application-level Python parent.
|
43
|
+
# @return [PoisePython::Resources::PythonRuntime::Resource, nil]
|
44
|
+
def app_state_python(python=Poise::NOT_PASSED)
|
45
|
+
unless python == Poise::NOT_PASSED
|
46
|
+
app_state[:python] = python
|
47
|
+
end
|
48
|
+
app_state[:python]
|
49
|
+
end
|
50
|
+
|
51
|
+
# A merged hash of environment variables for both the application state
|
52
|
+
# and parent python.
|
53
|
+
#
|
54
|
+
# @return [Hash<String, String>]
|
55
|
+
def app_state_environment_python
|
56
|
+
env = app_state_environment
|
57
|
+
env = env.merge(parent_python.python_environment) if parent_python
|
58
|
+
env
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# A helper mixin for Python application providers.
|
63
|
+
module Provider
|
64
|
+
include PoiseApplication::AppMixin::Provider
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'poise_application_python/resources'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'poise_application/error'
|
18
|
+
|
19
|
+
module PoiseApplicationPython
|
20
|
+
# Base exception class for poise-application-python errors.
|
21
|
+
#
|
22
|
+
# @since 4.0.0
|
23
|
+
class Error < PoiseApplication::Error
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'poise_application_python/resources/celery_beat'
|
18
|
+
require 'poise_application_python/resources/celery_config'
|
19
|
+
require 'poise_application_python/resources/celery_worker'
|
20
|
+
require 'poise_application_python/resources/django'
|
21
|
+
require 'poise_application_python/resources/gunicorn'
|
22
|
+
require 'poise_application_python/resources/pip_requirements'
|
23
|
+
require 'poise_application_python/resources/python'
|
24
|
+
require 'poise_application_python/resources/python_execute'
|
25
|
+
require 'poise_application_python/resources/python_package'
|
26
|
+
require 'poise_application_python/resources/virtualenv'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'poise_application_python/resources/celery_worker'
|
18
|
+
|
19
|
+
|
20
|
+
module PoiseApplicationPython
|
21
|
+
module Resources
|
22
|
+
# (see CeleryBeat::Resource)
|
23
|
+
# @since 4.0.0
|
24
|
+
module CeleryBeat
|
25
|
+
class Resource < PoiseApplicationPython::Resources::CeleryWorker::Resource
|
26
|
+
provides(:application_celery_beat)
|
27
|
+
end
|
28
|
+
|
29
|
+
class Provider < PoiseApplicationPython::Resources::CeleryWorker::Provider
|
30
|
+
provides(:application_celery_beat)
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# (see PoiseApplication::ServiceMixin#service_options)
|
35
|
+
def service_options(resource)
|
36
|
+
super
|
37
|
+
resource.command("#{new_resource.python} -m celery --app=#{new_resource.app_module} beat")
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'uri'
|
18
|
+
|
19
|
+
require 'chef/provider'
|
20
|
+
require 'chef/resource'
|
21
|
+
require 'poise'
|
22
|
+
require 'poise_application'
|
23
|
+
require 'poise_python'
|
24
|
+
|
25
|
+
require 'poise_application_python/app_mixin'
|
26
|
+
require 'poise_application_python/error'
|
27
|
+
|
28
|
+
|
29
|
+
module PoiseApplicationPython
|
30
|
+
module Resources
|
31
|
+
# (see CeleryConfig::Resource)
|
32
|
+
# @since 4.0.0
|
33
|
+
module CeleryConfig
|
34
|
+
# An `application_celery_config` resource to configure Celery workers.
|
35
|
+
#
|
36
|
+
# @since 4.0.0
|
37
|
+
# @provides application_celery_config
|
38
|
+
# @action deploy
|
39
|
+
# @example
|
40
|
+
# application '/srv/myapp' do
|
41
|
+
# git '...'
|
42
|
+
# pip_requirements
|
43
|
+
# celery_config do
|
44
|
+
# options do
|
45
|
+
# broker_url '...'
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
# celeryd
|
49
|
+
# end
|
50
|
+
class Resource < Chef::Resource
|
51
|
+
include PoiseApplicationPython::AppMixin
|
52
|
+
provides(:application_celery_config)
|
53
|
+
actions(:deploy)
|
54
|
+
|
55
|
+
attribute('', template: true, default_source: 'celeryconfig.py.erb')
|
56
|
+
# @!attribute group
|
57
|
+
# Owner for the Django application, defaults to application group.
|
58
|
+
# @return [String]
|
59
|
+
attribute(:group, kind_of: String, default: lazy { parent && parent.group })
|
60
|
+
# @!attribute owner
|
61
|
+
# Owner for the Django application, defaults to application owner.
|
62
|
+
# @return [String]
|
63
|
+
attribute(:owner, kind_of: String, default: lazy { parent && parent.owner })
|
64
|
+
attribute(:path, kind_of: String, default: lazy { default_path })
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def default_path
|
69
|
+
if ::File.directory?(name)
|
70
|
+
::File.join(name, 'celeryconfig.py')
|
71
|
+
else
|
72
|
+
name
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Provider for `application_celery_config`.
|
78
|
+
#
|
79
|
+
# @since 4.0.0
|
80
|
+
# @see Resource
|
81
|
+
# @provides application_celery_config
|
82
|
+
class Provider < Chef::Provider
|
83
|
+
include PoiseApplicationPython::AppMixin
|
84
|
+
provides(:application_celery_config)
|
85
|
+
|
86
|
+
# `deploy` action for `application_celery_config`. Writes config file.
|
87
|
+
#
|
88
|
+
# @return [void]
|
89
|
+
def action_deploy
|
90
|
+
notifying_block do
|
91
|
+
write_config
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def write_config
|
98
|
+
file new_resource.path do
|
99
|
+
content new_resource.content
|
100
|
+
mode '640'
|
101
|
+
owner new_resource.owner
|
102
|
+
group new_resource.group
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015, Noah Kantrowitz
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'chef/provider'
|
18
|
+
require 'chef/resource'
|
19
|
+
|
20
|
+
require 'poise_application_python/service_mixin'
|
21
|
+
|
22
|
+
|
23
|
+
module PoiseApplicationPython
|
24
|
+
module Resources
|
25
|
+
# (see CeleryWorker::Resource)
|
26
|
+
# @since 4.0.0
|
27
|
+
module CeleryWorker
|
28
|
+
class Resource < Chef::Resource
|
29
|
+
include PoiseApplicationPython::ServiceMixin
|
30
|
+
provides(:application_celery_worker)
|
31
|
+
|
32
|
+
attribute(:app_module, kind_of: [String, NilClass], default: lazy { default_app_module })
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# Compute the default application module to pass to gunicorn. This
|
37
|
+
# checks the app state and then looks for commonly used filenames.
|
38
|
+
# Raises an exception if no default can be found.
|
39
|
+
#
|
40
|
+
# @return [String]
|
41
|
+
def default_app_module
|
42
|
+
# If set in app_state, use that.
|
43
|
+
return app_state[:python_celery_module] if app_state[:python_celery_module]
|
44
|
+
# If a Django settings module is set, use everything by the last
|
45
|
+
# dotted component of it. to_s handles nil since that won't match.
|
46
|
+
return $1 if app_state_environment[:DJANGO_SETTINGS_MODULE].to_s =~ /^(.+?)\.[^.]+$/
|
47
|
+
files = Dir.exist?(path) ? Dir.entries(path) : []
|
48
|
+
# Try to find a known filename.
|
49
|
+
candidate_file = %w{tasks.py task.py celery.py main.py app.py application.py}.find {|file| files.include?(file) }
|
50
|
+
# Try the first Python file. Do I really want this?
|
51
|
+
candidate_file ||= files.find {|file| file.end_with?('.py') }
|
52
|
+
if candidate_file
|
53
|
+
::File.basename(candidate_file, '.py')
|
54
|
+
else
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
class Provider < Chef::Provider
|
62
|
+
include PoiseApplicationPython::ServiceMixin
|
63
|
+
provides(:application_celery_worker)
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
# (see PoiseApplication::ServiceMixin#service_options)
|
68
|
+
def service_options(resource)
|
69
|
+
super
|
70
|
+
raise PoiseApplicationPython::Error.new("Unable to determine app module for #{new_resource}") unless new_resource.app_module
|
71
|
+
resource.command("#{new_resource.python} -m celery --app=#{new_resource.app_module} worker")
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|