skyrunner 0.1.1 → 0.1.2
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 +4 -4
- data/bin/skyrunner +1 -3
- data/lib/generators/sky_runner/install/templates/skyrunner.rb +0 -3
- data/lib/skyrunner/job.rb +1 -1
- data/lib/skyrunner/version.rb +1 -1
- data/lib/skyrunner.rb +11 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49176f855293135111d70129a79f8f6099d775f6
|
4
|
+
data.tar.gz: fe7cb68a221e708c668e49f950161f4db9d67542
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff7a55a80f9a5710ddddcec9b0df187d098557667e49db60c6a90386b7e006b9b08437cb02dd4791396169acc378d44dcf0bc633c582b11f6b62f751fd779538
|
7
|
+
data.tar.gz: 1df498dd88128acb06800004a76208292881c10e372d180cb2d7f38ef28cb7d8860821aa1f30ee11eaf28971bf2f35159fc7471b0734512d15eaf44cda0099b0
|
data/bin/skyrunner
CHANGED
@@ -32,14 +32,12 @@ opts = Trollop::options do
|
|
32
32
|
|
33
33
|
opt :dynamo_db_table_name, "DynamoDB table to use for job state.", default: "skyrunner_jobs", type: :string
|
34
34
|
opt :sqs_queue_name, "SQS queue use for tasks.", default: "skyrunner_tasks", type: :string
|
35
|
-
opt :namespace, "Namespace of jobs to consume.", default: "default", type: :string
|
36
35
|
opt :batch_size, "Number of tasks to consume per batch.", default: 10
|
37
36
|
opt :num_threads, "Number of consumer threads.", default: 10
|
38
37
|
end
|
39
38
|
|
40
39
|
SkyRunner.dynamo_db_table_name = opts[:dynamo_db_table_name]
|
41
40
|
SkyRunner.sqs_queue_name = opts[:sqs_queue_name]
|
42
|
-
SkyRunner.job_namespace = opts[:namespace]
|
43
41
|
SkyRunner.consumer_batch_size = opts[:batch_size].to_i
|
44
42
|
SkyRunner.num_threads = opts[:num_threads].to_i
|
45
43
|
|
@@ -59,6 +57,6 @@ when "consume"
|
|
59
57
|
when "test"
|
60
58
|
$: << "."
|
61
59
|
require "#{File.dirname(__FILE__)}/../jobs/example_job"
|
62
|
-
ExampleJobModule::ExampleJob.new.execute!(number_of_tasks:
|
60
|
+
ExampleJobModule::ExampleJob.new.execute!(number_of_tasks: 100)
|
63
61
|
SkyRunner.consume!
|
64
62
|
end
|
@@ -5,9 +5,6 @@ SkyRunner.setup do |config|
|
|
5
5
|
config.dynamo_db_table_name = "skyrunner_jobs_#{Rails.env}"
|
6
6
|
config.sqs_queue_name = "skyrunner_tasks_#{Rails.env}"
|
7
7
|
|
8
|
-
# Customzie this to change the namespace of jobs enqueued and consumed by this application.
|
9
|
-
config.job_namespace = Rails.application.class.parent_name.underscore
|
10
|
-
|
11
8
|
# Set the number of tasks for a consumer to pull and run from SQS at a time. (Max 10, default 10)
|
12
9
|
#
|
13
10
|
# config.consumer_batch_size = 10
|
data/lib/skyrunner/job.rb
CHANGED
@@ -34,7 +34,7 @@ module SkyRunner::Job
|
|
34
34
|
table = SkyRunner.dynamo_db_table
|
35
35
|
queue = SkyRunner.sqs_queue
|
36
36
|
|
37
|
-
record = table.items.put(job_id: job_id,
|
37
|
+
record = table.items.put(job_id: job_id, class: self.class.name, args: args.to_json, total_tasks: 1, completed_tasks: 0, done: 0, failed: 0)
|
38
38
|
|
39
39
|
pending_args = []
|
40
40
|
|
data/lib/skyrunner/version.rb
CHANGED
data/lib/skyrunner.rb
CHANGED
@@ -74,7 +74,7 @@ module SkyRunner
|
|
74
74
|
1.upto(SkyRunner::num_threads) do
|
75
75
|
threads << Thread.new do
|
76
76
|
loop do
|
77
|
-
break if SkyRunner::stop_consuming? && local_queue.
|
77
|
+
break if SkyRunner::stop_consuming? && local_queue.empty?
|
78
78
|
|
79
79
|
sleep 1 unless local_queue.size > 0
|
80
80
|
|
@@ -116,24 +116,24 @@ module SkyRunner
|
|
116
116
|
|
117
117
|
received_messages = []
|
118
118
|
|
119
|
-
|
119
|
+
batch_size = [1, [SkyRunner.consumer_batch_size, SQS_MAX_BATCH_SIZE].min].max
|
120
|
+
|
121
|
+
queue.receive_messages(limit: batch_size, wait_time_seconds: 5) do |message|
|
120
122
|
received_messages << [message, JSON.parse(message.body)]
|
121
123
|
end
|
122
124
|
|
123
125
|
next unless received_messages.size > 0
|
124
126
|
|
125
127
|
table.batch_get(:all, received_messages.map { |m| m[1]["job_id"] }.uniq, consistent_read: true) do |record|
|
126
|
-
received_messages.select { |m| m[1]["job_id"] == record["job_id"] }.
|
127
|
-
message = received_message
|
128
|
-
job_id =
|
129
|
-
|
130
|
-
if record["namespace"] == SkyRunner.job_namespace && record["failed"] == 0 && error_queue.size == 0
|
131
|
-
start_time = Time.now
|
128
|
+
received_messages.select { |m| m[1]["job_id"] == record["job_id"] }.each do |received_message|
|
129
|
+
message, message_data = received_message
|
130
|
+
job_id = message_data["job_id"]
|
132
131
|
|
132
|
+
if record["failed"] == 0 && error_queue.empty?
|
133
133
|
begin
|
134
134
|
klass = Kernel.const_get(record["class"])
|
135
|
-
task_args =
|
136
|
-
local_queue.push([klass, job_id, task_args,
|
135
|
+
task_args = message_data["task_args"]
|
136
|
+
local_queue.push([klass, job_id, task_args, message])
|
137
137
|
rescue NameError => e
|
138
138
|
log :error, "Task Failed: No such class #{record["class"]} #{e.message}"
|
139
139
|
yield e if block_given?
|
@@ -143,7 +143,7 @@ module SkyRunner
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
-
threads.each
|
146
|
+
threads.each(&:join)
|
147
147
|
|
148
148
|
true
|
149
149
|
end
|
@@ -184,9 +184,6 @@ module SkyRunner
|
|
184
184
|
mattr_accessor :sqs_message_retention_period
|
185
185
|
@@sqs_message_retention_period = 345600
|
186
186
|
|
187
|
-
mattr_accessor :job_namespace
|
188
|
-
@@job_namespace = "default"
|
189
|
-
|
190
187
|
mattr_accessor :consumer_batch_size
|
191
188
|
@@consumer_batch_size = 10
|
192
189
|
|