Module: IronWorkerNG::Code::Runtime::PHP

Includes:
Feature::Common::MergeExec::InstanceMethods
Defined in:
lib/iron_worker_ng/code/runtime/php.rb

Instance Method Summary collapse

Methods included from Feature::Common::MergeExec::InstanceMethods

#merge_exec

Instance Method Details

#runtime_bundle(container, local = false) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/iron_worker_ng/code/runtime/php.rb', line 7

def runtime_bundle(container, local = false)
  container.get_output_stream(@dest_dir + '__runner__.php') do |runner|
    runner.write <<PHP_RUNNER
<?php
/* #{IronWorkerNG.full_version} */

function getArgs($assoc = true) {
  global $argv;

  $args = array('task_id' => null, 'dir' => null, 'payload' => array(), 'config' => null, 'schedule_id' => null);

  foreach ($argv as $k => $v) {
    if (empty($argv[$k + 1])) continue;

    if ($v == '-id') $args['task_id'] = $argv[$k + 1];
    if ($v == '-d')  $args['dir']     = $argv[$k + 1];
    if ($v == '-schedule_id') $args['schedule_id'] = $argv[$k + 1];

    if ($v == '-payload' && file_exists($argv[$k + 1])) {
      $args['payload'] = file_get_contents($argv[$k + 1]);

      $parsed_payload = json_decode($args['payload'], $assoc);

      if ($parsed_payload != null) {
$args['payload'] = $parsed_payload;
      }
    }

    if ($v == '-config' && file_exists($argv[$k + 1])) {
      $args['config'] = file_get_contents($argv[$k + 1]);

      $parsed_config = json_decode($args['config'], $assoc);

      if ($parsed_config != null) {
  $args['config'] = $parsed_config;
      }
    }
  }

  return $args;
}

function getPayload($assoc = false) {
  $args = getArgs($assoc);

  return $args['payload'];
}

function getConfig($assoc = true){
  $args = getArgs($assoc);

  return $args['config'];
}

require '#{File.basename(@exec.path)}';
PHP_RUNNER
  end
end

#runtime_run_code(local, params) ⇒ Object



66
67
68
69
70
# File 'lib/iron_worker_ng/code/runtime/php.rb', line 66

def runtime_run_code(local, params)
  <<RUN_CODE
TERM=dumb php __runner__.php #{params}
RUN_CODE
end