Comments (2)
Hi @leoplct
Firstly, the ['a', 'b', 'c'].each do |report|
part of the definition won't work as expected since each :work_step
emitted won't have the report
parameter.
# ...
['a', 'b', 'c'].each do |report|
task :work_step
end
# ...
Instead, you will need to use the for_each
method, explained in the Data Driven Process Definitions section, to yield each report to be run by the work_step
task.
# ...
for_each :list_of_reports do
task :work_step
end
# ...
Where list_of_reports
is an iterator method:
# ...
def list_of_reports
yield ...
end
# ...
Secondly, in the implementation of the work_step
and end
methods, you don't need to re-enqueue the SyncReportJob
and FinalActiveJob
jobs (using perform_later
), since these methods will already be executing as background jobs.
I.e.
#...
def work_step(report)
p "REPORT: #{report}"
SyncReportJob.perform(report) # use perform instead, to execute immediately
end
#...
Thirdly, as you wanted, this process definition will result in each work_step
tasks being executed concurrently and once they have all successfully completed, the final_step
will be executed.
Note: I've rename end
to be final_step
so as not to be confused with with Ruby's end
.
# ...
define_process do
concurrent do
for_each :report do
task :work_step
end
end
task :final_step
end
# ...
And the DAG will be:
/ work_step (a) \
/ \
o - - work_step (b) - - final_step - O
\ /
\ work_step (c) /
Finally, I notice that the end
step takes id
as an argument, but this is never specified anywhere, so I imagine it will probably be passed in when the process gets defined, so it should be specified as a parameter:
# ...
define_process :id do
# ...
end
# ...
Rewriting your example to make the changes, as follows:
module ReportsProcess
extend Taskinator::Definition
define_process :id do
concurrent do
for_each :list_of_reports do
task :work_step
end
end
task :final_step
end
def list_of_reports(id)
['a', 'b', 'c'].each do |r|
yield r
end
end
def work_step(report)
p "REPORT: #{report}"
SyncReportJob.perform(report)
end
def final_step(id)
FinalActiveJob.perform(id)
end
end
And then running this process, providing the id
parameter:
id = 1234 # provide ID
process = ReportsProcess.create_process(id)
process.enqueue!
NOTE:
If you have already implemented SyncReportJob
and FinalActiveJob
as jobs you can use the job
directive instead of task
and taskinator will enqueue and process your jobs. See Reusing ActiveJob jobs for more details.
The code, refactored to use job
instead:
module ReportsProcess
extend Taskinator::Definition
define_process :id do
concurrent do
for_each :report do
job SyncReportJob
end
end
job FinalActiveJob
end
def list_of_reports(id)
['a', 'b', 'c'].each do |r|
yield r
end
end
end
Hope this helps!
from taskinator.
Closing due to inactivity
from taskinator.
Related Issues (10)
- Add support for ActiveJob HOT 1
- undefined method `create_resque_adapter' HOT 1
- Include definition in instrumentation payload
- Better test/spec support
- Is there any plan for progress and dependency visualization?
- Taskinator::Api::Processes fails when one of the classes doesn't exist any more HOT 1
- job method doesn't work properly HOT 6
- Failures handling best practice HOT 4
- Debugging best practice HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from taskinator.