foreman_hooks 0.3.15 → 0.3.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 87442c737ac9a7e0a5dfa830a53ebbce69121da6
4
- data.tar.gz: 9b455bf7f174ade8aa225cc961068f0e4fde84a8
2
+ SHA256:
3
+ metadata.gz: 4dc282696356d27aa5a60add59c36a5cad8b56efff3b2d596a2d5046e9802f84
4
+ data.tar.gz: b596f8a8701a4f5bc3ced2c26ffd156cf38b113040f04db031efecf726fe3a1b
5
5
  SHA512:
6
- metadata.gz: 27d082d0c28f8406a081b5b6be1be72aad4b5f74d7790735c2a12d2a32984da91a438f6face9676cd472a720eef639755f35fe7fd7c13a1a955c0da96f18f851
7
- data.tar.gz: 7f861b52fb1dc7ae207fc4d3218afee8c6d01c5e423d9a2ad36a1ea1a93dde521963faace55cb494adbc52b4138ef7c5d305becb7ad38216ddd35a9337340098
6
+ metadata.gz: db3174053c929c862debecf523943cb3f7c87dd902407579a9295f12de9f17e0d90998ad7e0d828a13303db05a9deed65181703fc4bcb40063647741561b8e51
7
+ data.tar.gz: ab116e0a5052dae4a9e0f219bedf10eb217b481a7e2f00a070eca1c736dcf196ca15cd4712f814f0bbe06bd7fa4f04ce6c03d9d1aae00ee9fc3c9dd6575823a7
data/README.md CHANGED
@@ -71,12 +71,22 @@ automatically trigger a rollback of the action. A rollback is performed as
71
71
  an opposite action (e.g. for DHCP record creation a rollback action is
72
72
  destroy).
73
73
 
74
- To add hooks to these, use these event names:
74
+ The following hooks are executed during `around_save` Rails callback:
75
75
 
76
76
  * `create`
77
77
  * `update`
78
+
79
+ The following hooks are executed during `on_destroy` Rails callback:
80
+
78
81
  * `destroy`
79
82
 
83
+ The following hooks are executed during `after_commit` Rails callback:
84
+
85
+ * `postcreate`
86
+ * `postupdate`
87
+
88
+ The major difference between `create` and `postcreate` (or update respectively) is how late the hook is called during save operation. In the former case when a hook fails it starts rollback and operation can be still cancelled. In the latter case object was already saved and there is no way of cancelling the operation, but all referenced data should be properly loaded. The advice is to use the latter hooks as they will likely contain all the required data (e.g. nested parameters).
89
+
80
90
  Orchestration hooks can be given a priority by prefixing the filename with the
81
91
  priority number, therefore it is possible to order them before or after
82
92
  built-in orchestration steps (before DNS records are created for example).
@@ -133,7 +143,7 @@ may want to ensure stdin is closed to prevent pipe buffer from filling.
133
143
 
134
144
  Some arguments are available as environment variables:
135
145
 
136
- Variable | Description
146
+ Variable | Description
137
147
  -------- | -----------
138
148
  FOREMAN_HOOKS_USER | Username of Foreman user
139
149
 
@@ -68,7 +68,7 @@ module ForemanHooks
68
68
  end
69
69
 
70
70
  def attach_hook(klass, events)
71
- if events.keys.detect { |event| ['create', 'update', 'destroy'].include? event }
71
+ if events.keys.detect { |event| ['create', 'update', 'destroy', 'postcreate', 'postupdate'].include? event }
72
72
  unless klass.ancestors.include?(ForemanHooks::OrchestrationHook)
73
73
  logger.debug "Extending #{klass} with foreman_hooks orchestration hooking support"
74
74
  klass.send(:include, ForemanHooks::OrchestrationHook)
@@ -12,6 +12,7 @@ module ForemanHooks::OrchestrationHook
12
12
  def queue_hooks_validate
13
13
  return unless errors.empty?
14
14
  queue_hooks(new_record? ? 'create' : 'update')
15
+ queue_hooks(new_record? ? 'postcreate' : 'postupdate')
15
16
  end
16
17
 
17
18
  def queue_hooks_destroy
@@ -33,10 +34,10 @@ module ForemanHooks::OrchestrationHook
33
34
  hooks.each do |filename|
34
35
  basename = File.basename(filename)
35
36
  priority = basename =~ /^(\d+)/ ? $1 : 10000 + (counter += 1)
36
- logger.debug "Queuing hook #{basename} for #{self.class.to_s}##{event} at priority #{priority}"
37
- queue.create(:name => "Hook: #{basename}", :priority => priority.to_i,
38
- :action => [HookRunner.new(filename, self, event.to_s),
39
- event.to_s == 'destroy' ? :hook_execute_del : :hook_execute_set])
37
+ logger.debug "Queuing hook #{filename} for #{self.class.to_s}##{event} at priority #{priority}"
38
+ queue_to_use = (event =~ /^post/) ? post_queue : queue
39
+ queue_to_use.create(:name => "Hook: #{filename}", :priority => priority.to_i,
40
+ :action => [HookRunner.new(filename, self, event.to_s), event.to_s == 'destroy' ? :hook_execute_del : :hook_execute_set])
40
41
  end
41
42
  end
42
43
 
@@ -54,7 +55,7 @@ module ForemanHooks::OrchestrationHook
54
55
  end
55
56
 
56
57
  def hook_execute_set
57
- @obj.exec_hook(@filename, @event == 'destroy' ? 'create' : @event, *args)
58
+ @obj.exec_hook(@filename, @event, *args)
58
59
  end
59
60
 
60
61
  def hook_execute_del
@@ -24,7 +24,7 @@ namespace :hooks do
24
24
  events = ActiveRecord::Callbacks::CALLBACKS.map(&:to_s).reject { |e| e.start_with?('around_') }
25
25
 
26
26
  # 2. List Foreman orchestration callbacks
27
- events.concat(['create', 'destroy', 'update']) if model.included_modules.include?(Orchestration)
27
+ events.concat(['create', 'destroy', 'update', 'postcreate', 'postupdate']) if model.included_modules.include?(Orchestration)
28
28
 
29
29
  # 3. List custom define_callbacks/define_model_callbacks
30
30
  callbacks = model.methods.map { |m| $1 if m =~ /\A_([a-z]\w+)_callbacks\z/ }.compact
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_hooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.15
4
+ version: 0.3.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominic Cleal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-18 00:00:00.000000000 Z
11
+ date: 2019-12-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Plugin engine for Foreman that enables running custom hook scripts on
14
14
  Foreman events
@@ -57,8 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  - !ruby/object:Gem::Version
58
58
  version: '0'
59
59
  requirements: []
60
- rubyforge_project:
61
- rubygems_version: 2.6.14.1
60
+ rubygems_version: 3.0.3
62
61
  signing_key:
63
62
  specification_version: 4
64
63
  summary: Run custom hook scripts on Foreman events