spec/jobs.rb in asynchronic-0.1.0 vs spec/jobs.rb in asynchronic-0.2.0
- old
+ new
@@ -1,148 +1,169 @@
class BasicJob < Asynchronic::Job
- define do
- data[:output] = data[:input] + 1
+ def call
+ params[:input] + 1
end
end
class SequentialJob < Asynchronic::Job
- define do
- define_job Step1
- define_job Step2, dependency: Step1
+ def call
+ async Step1, input: params[:input]
+
+ async Step2, dependency: Step1,
+ input: params[:input]
+
+ nil
end
class Step1 < Asynchronic::Job
- define do
- data[:partial] = data[:input] * 10
+ def call
+ params[:input] * 10
end
end
class Step2 < Asynchronic::Job
- define do
- data[:output] = data[:partial] / 100
+ def call
+ params[:input] / 10
end
end
end
class GraphJob < Asynchronic::Job
- define do
- define_job Sum
- define_job TenPercent, dependency: Sum
- define_job TwentyPercent, dependency: Sum
- define_job Total, dependencies: [TenPercent, TwentyPercent]
+ def call
+ async Sum, input: params[:input]
+
+ async TenPercent, input: result(Sum)
+
+ async TwentyPercent, input: result(Sum)
+
+ async Total, '10%' => result(TenPercent),
+ '20%' => result(TwentyPercent)
+
+ result Total
end
class Sum < Asynchronic::Job
- define do
- data[:sum] = data[:input] + 100
+ def call
+ params[:input] + 100
end
end
class TenPercent < Asynchronic::Job
- define do
- data['10%'] = data[:sum] * 0.1
+ def call
+ params[:input] * 0.1
end
end
class TwentyPercent < Asynchronic::Job
- define do
- data['20%'] = data[:sum] * 0.2
+ def call
+ params[:input] * 0.2
end
end
class Total < Asynchronic::Job
- define do
- data[:output] = {'10%' => data['10%'], '20%' => data['20%']}
+ def call
+ {'10%' => params['10%'], '20%' => params['20%']}
end
end
end
class ParallelJob < Asynchronic::Job
- define do
- data[:times].times do |i|
- define_job Child, local: {index: i}
+ def call
+ params[:times].times do |i|
+ async Child, input: params[:input], index: i
end
end
class Child < Asynchronic::Job
- define do
- data["key_#{index}"] = data[:input] * index
+ def call
+ params[:input] * params[:index]
end
end
end
class NestedJob < Asynchronic::Job
- define do
- define_job Level1
+ def call
+ async Level1, input: params[:input]
+ result Level1
end
class Level1 < Asynchronic::Job
- define do
- data[:input] += 1
- define_job Level2
+ def call
+ async Level2, input: params[:input] + 1
+ result Level2
end
class Level2 < Asynchronic::Job
- define do
- data[:output] = data[:input] ** 2
+ def call
+ params[:input] ** 2
end
end
end
end
-class DependencyAliasJob < Asynchronic::Job
- define do
- define_job Write, local: {text: 'Take'}, alias: :word_1
- define_job Write, local: {text: 'it'}, alias: :word_2, dependency: :word_1
- define_job Write, local: {text: 'easy'}, alias: :word_3, dependency: :word_2
+class AliasJob < Asynchronic::Job
+ def call
+ async Write, alias: :word_1,
+ text: 'Take'
+
+ async Write, alias: :word_2,
+ text: 'it',
+ prefix: result(:word_1)
+
+ async Write, alias: :word_3,
+ text: 'easy',
+ prefix: result(:word_2)
+
+ result :word_3
end
class Write < Asynchronic::Job
- define do
- data[:text] = "#{data[:text]} #{text}".strip
+ def call
+ [params[:prefix], params[:text]].compact.join(' ')
end
end
end
class CustomQueueJob < Asynchronic::Job
queue :queue_1
- define do
- define_job Reverse, queue: :queue_2
+ def call
+ async Reverse, queue: :queue_2, input: params[:input]
+ result Reverse
end
class Reverse < Asynchronic::Job
queue :queue_3
- define do
- data[:output] = data[:input].reverse
+ def call
+ params[:input].reverse
end
end
end
class ExceptionJob < Asynchronic::Job
- define do
+ def call
raise 'Error for test'
end
end
class InnerExceptionJob < Asynchronic::Job
- define do
- define_job ExceptionJob
+ def call
+ async ExceptionJob
end
end
class WorkerJob < Asynchronic::Job
- define do
+ def call
end
end
\ No newline at end of file