Module: MiGA::Dataset::Hooks

Includes:
Common::Hooks
Included in:
MiGA::Dataset
Defined in:
lib/miga/dataset/hooks.rb

Overview

Helper module including specific functions to handle dataset hooks. Supported events:

  • on_create(): When first created

  • on_load(): When loaded

  • on_save(): When saved

  • on_remove(): When removed

  • on_activate(): When activated

  • on_inactivate(): When inactivated

  • on_result_ready(result): When any result is ready, with key result

  • on_result_ready_Common::WithResult#result(): When result is ready

  • on_preprocessing_ready(): When preprocessing is complete

Supported hooks:

  • run_lambda(lambda, argsā€¦)

  • recalculate_status()

  • clear_run_counts()

  • run_cmd(cmd)

Internal hooks:

  • _pull_result_hooks()

Instance Method Summary collapse

Methods included from Common::Hooks

#add_hook, #hook_run_lambda, #hooks, #pull_hook

Instance Method Details

#default_hooksObject

Dataset hooks triggered by default



27
28
29
30
31
32
33
34
35
# File 'lib/miga/dataset/hooks.rb', line 27

def default_hooks
  {
    on_create: [[:recalculate_status]],
    on_activate: [[:clear_run_counts], [:recalculate_status]],
    on_inactivate: [[:recalculate_status]],
    on_result_ready: [[:_pull_result_hooks]],
    on_preprocessing_ready: [[:clear_run_counts], [:recalculate_status]],
  }
end

#hook__pull_result_hooks(_hook_args, event_args) ⇒ Object

Dataset Action :pull_result_hooks([], [res]) Pull the hook specific to the type of result



71
72
73
74
# File 'lib/miga/dataset/hooks.rb', line 71

def hook__pull_result_hooks(_hook_args, event_args)
  pull_hook(:"on_result_ready_#{event_args.first}", *event_args)
  pull_hook(:on_preprocessing_ready) if done_preprocessing?
end

#hook_clear_run_counts(_hook_args, _event_args) ⇒ Object

Clear metadata from run counts



39
40
41
42
43
44
45
46
# File 'lib/miga/dataset/hooks.rb', line 39

def hook_clear_run_counts(_hook_args, _event_args)
  
    .data.keys
    .select { |k| k.to_s =~ /^_try_/ }
    .each { |k| [k] = nil }
  [:_step] = nil
  save
end

#hook_recalculate_status(_hook_args, _event_args) ⇒ Object

Recalculate the dataset status and save in metadata



50
51
52
# File 'lib/miga/dataset/hooks.rb', line 50

def hook_recalculate_status(_hook_args, _event_args)
  recalculate_status
end

#hook_run_cmd(hook_args, event_args) ⇒ Object

Run cmd in the command-line with {variables}: dataset, project, project_name, miga, object (if defined for the event)

  • hook_args: [cmd]

  • event_args: [object (optional)]



59
60
61
62
63
64
65
66
# File 'lib/miga/dataset/hooks.rb', line 59

def hook_run_cmd(hook_args, event_args)
  Process.wait(
    spawn hook_args.first.miga_variables(
      dataset: name, project: project.path, project_name: project.name,
      miga: MiGA::MiGA.root_path, object: event_args.first
    )
  )
end