simple_worker 0.0.8 → 0.0.9

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.
Files changed (2) hide show
  1. data/lib/simple_worker.rb +49 -5
  2. metadata +2 -2
data/lib/simple_worker.rb CHANGED
@@ -21,11 +21,12 @@ module SimpleWorker
21
21
  end
22
22
  options = {"code"=>mystring, "class_name"=>class_name}
23
23
  response = run_http(@host, @access_key, @secret_key, :post, "code/put", nil, options)
24
- puts "response=" + response
24
+ # puts "response=" + response
25
25
  return ActiveSupport::JSON.decode(response)
26
26
  end
27
27
 
28
-
28
+ #
29
+ # data:
29
30
  def queue(class_name, data={})
30
31
 
31
32
  params = nil
@@ -35,20 +36,63 @@ module SimpleWorker
35
36
  hash_to_send = {}
36
37
  hash_to_send["data"] = data
37
38
  hash_to_send["class_name"] = class_name
38
- puts 'hash_to_send=' + hash_to_send.inspect
39
+ # puts 'hash_to_send=' + hash_to_send.inspect
39
40
  response = run_http(@host, @access_key, @secret_key, :put, "queue/add", hash_to_send, params)
40
- puts "response=" + response
41
+ # puts "response=" + response
42
+ return ActiveSupport::JSON.decode(response)
43
+ end
44
+
45
+ #
46
+ # schedule: hash of scheduling options that can include:
47
+ # Required:
48
+ # - start_at: Time of first run - DateTime or Time object.
49
+ # Optional:
50
+ # - run_every: Time in seconds between runs. If ommitted, task will only run once.
51
+ # - delay_type: Fixed Rate or Fixed Delay. Default is fixed_delay.
52
+ # - end_at: Scheduled task will stop running after this date (optional, if ommitted, runs forever or until cancelled)
53
+ # - run_times: Task will run exactly :run_times. For instance if :run_times is 5, then the task will run 5 times.
54
+ #
55
+ def schedule(class_name, data, schedule)
56
+ raise "Schedule must be a hash." if !schedule.is_a? Hash
57
+ params = nil
58
+ if !data.is_a?(Array)
59
+ data = [data]
60
+ end
61
+ hash_to_send = {}
62
+ hash_to_send["data"] = data
63
+ hash_to_send["class_name"] = class_name
64
+ hash_to_send["schedule"] = schedule
65
+ # puts 'hash_to_send=' + hash_to_send.inspect
66
+ response = run_http(@host, @access_key, @secret_key, :put, "queue/schedule", hash_to_send, params)
67
+ # puts "response=" + response
41
68
  return ActiveSupport::JSON.decode(response)
42
69
  end
43
70
 
71
+ #
72
+ #
73
+ #
74
+ def get_scheduled_tasks(schedule_id)
75
+ params = nil
76
+ if !data.is_a?(Array)
77
+ data = [data]
78
+ end
79
+ hash_to_send = {}
80
+ hash_to_send["data"] = data
81
+ hash_to_send["class_name"] = class_name
82
+ # puts 'hash_to_send=' + hash_to_send.inspect
83
+ response = run_http(@host, @access_key, @secret_key, :put, "queue/add", hash_to_send, params)
84
+ # puts "response=" + response
85
+ return ActiveSupport::JSON.decode(response)
86
+ end
44
87
 
45
88
  def status(task_id)
46
89
  data = {"task_id"=>task_id}
47
90
  #puts run_http(@access_key, @secret_key, :post, "queue/status", nil, {"task_id"=>@task_id})
48
91
  response = run_http(@host, @access_key, @secret_key, :get, "queue/status", nil, data)
49
- puts "response=" + response
92
+ # puts "response=" + response
50
93
  return ActiveSupport::JSON.decode(response)
51
94
  end
52
95
 
96
+
53
97
  end
54
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_worker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Reeder
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-03 00:00:00 -08:00
12
+ date: 2009-11-15 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15