serially 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDI4ZDNhOGNmOWY5NzdmZDQ2ZmQ0MTk0YmRiMTcxZDVkZWIwNDg0Mw==
4
+ YjA2NDZjZjI3YTYzYzUzODg2N2IzYTlhNjc4MzNlNDQzZWRmNzkxMA==
5
5
  data.tar.gz: !binary |-
6
- ZGMwODc1M2I1NWU5ZWQ4NTcyODlmM2I5ZTg3ZDI4OTU3ZjdhZjY2Mg==
6
+ ZjRiNjU3YWJkM2I3MzE0NmQ3YzBjZGFiODE0ZTg5NmY3MTU4NjFjMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTZiMjE0YzQwYTQxNzUyNWQwOThkMDc0MjA4OWU1MGM0YjllMzVjZjc1NjFk
10
- Y2Q0MGI2MWMxYjFmY2RhNDI3MTYyNTIwZmE0M2NiMDU5NWY2M2QxMDdmYjFi
11
- NTIzMTcyZmQzNjAzODAzMjFkNmQwZTJlMjEwYWUyZWNjZGU0OTA=
9
+ YmE3N2M3MWZlNmUwMTYyYjk4YmY3MTFlNmUzYzZkYjU5ZjRjN2Y0NjRiMWFk
10
+ NmMyMDJhZTY4M2YwZDNhMzAwNDgyZjI2NjdiYjA2MWMyYzY3ZTEwZGRmN2Uz
11
+ NmEzZTdlNzEyZTcwZjBiYWRmMGE0NzQ1Y2M5YzI2ZGEyMDkxMjg=
12
12
  data.tar.gz: !binary |-
13
- MmFmZWYxM2M4ODYxODRjNTYzNTE0ZDI3ZDE4MmI4MDU4ZjQ2N2E1OTAyYWZm
14
- N2JiMWEyZjExMmU2MjJmOGFhNzNkZmMzZGM3NjNjMWFjZTQ2NGUzMmUwYzRi
15
- ZmEyYTZmMjE2YzI3MGZhZjgxNjA5MzBjNzg5ZDMxM2Y3MmFkOTY=
13
+ ODFjZGRhZjc5YmE1ZTA5MDUwMDQxZjNhOGY2MDVhMjA4MzA1OWY3YjI4ODZj
14
+ MzM5OTJmNjIwZTQ0ODI2NzgxZGYxMDVhNjFiNTY4OTEyNzVmZjljY2QxNzI2
15
+ ZWU3ZDkwMjJhZTAxYjZkMjhjNjUwZjRlMDQwOTljOTNkODQyMzA=
data/.pryrc CHANGED
@@ -1 +1,21 @@
1
- require './spec/active_record_helper'
1
+ require './spec/active_record_helper'
2
+
3
+ class SimpleModel < ActiveRecord::Base
4
+ include Serially
5
+
6
+ self.table_name = 'simple_items'
7
+
8
+ serially do
9
+ task :model_step1 do |instance|
10
+ true
11
+ end
12
+ task :model_step2 do |instance|
13
+ ["OK", 'step 2 finished ok']
14
+ end
15
+ task :model_step3
16
+ end
17
+
18
+ def model_step3
19
+ [false, 'step 3 failed']
20
+ end
21
+ end
data/README.md CHANGED
@@ -3,14 +3,14 @@
3
3
  [![Build Status](https://circleci.com/gh/mikemarsian/serially.svg?&style=shield&circle-token=93a8f2925ebdd64032108118ef6e17eb3848d767)](https://circleci.com/gh/mikemarsian/serially)
4
4
  [![Code Climate](https://codeclimate.com/github/mikemarsian/serially/badges/gpa.svg)](https://codeclimate.com/github/mikemarsian/serially)
5
5
 
6
- Have you ever had a class that required a series of background tasks to run serially, strictly one after another? Than Serially is for you.
6
+ Have you ever had a class that required a series of background tasks to run serially, strictly one after another? Then Serially is for you.
7
7
  Declare the tasks using a simple DSL in the order you want them to to run. Serially will wrap them in a single job, and schedule it using Resque
8
- in a queue you specify (or a default one). The next task will run only if previous one finished successfully. All task runs are written to DB and can be inspected (if
9
- your class is an ActiveRecord object).
8
+ in a queue you specify (or a default one). The next task will run only if the previous one has finished successfully. All task run results are written to DB and can be inspected (that is if
9
+ your class is an ActiveRecord model).
10
10
 
11
11
  Check [this demo app][1] to see how Serially may be used in a Rails app.
12
12
 
13
- Note: Serially is under active development. If there is anything you miss in it, please let me know!
13
+ Note: Serially is under active development. If there is anything you miss in it, let me know!
14
14
 
15
15
  Twitter: @mikepolis Email: mike AT polischuk DOT net
16
16
 
@@ -70,8 +70,9 @@ class Post < ActiveRecord::Base
70
70
  end
71
71
  end
72
72
  ```
73
+ ### Start for Instance
73
74
 
74
- After creating a Post, you can run `post.serially.start!` to schedule your Post tasks to run serially. They will run one after the other in the scope of the same `Serially::Job`
75
+ After creating an instance of a Post, you can run `post.serially.start!` to schedule your Post tasks to run serially. They will run one after the other in the scope of the same `Serially::Job`
75
76
  in the default `serially` queue.
76
77
  An example run:
77
78
  ```ruby
@@ -89,6 +90,11 @@ Post 1 not published - bibliography is missing
89
90
  Post 2 reviewed by staff
90
91
  Post 2 not published - bibliography is missing
91
92
  ```
93
+ ### Start for Batch
94
+ If you want to schedule serially tasks for multiple instances, you can do it in a single call:
95
+ ```ruby
96
+ Post.start_batch!([post1.id, post2.id, post3.id])
97
+ ```
92
98
 
93
99
  ### Task Return Values
94
100
 
@@ -133,7 +139,7 @@ class Post
133
139
  end
134
140
  end
135
141
  ```
136
- `Serially::Job`'s of different instances of Post will all be scheduled in 'posts' queue, without any interference to each other.
142
+ Jobs for different instances of Post will all be scheduled in 'posts' queue, without any interference to each other.
137
143
 
138
144
  ### Blocks
139
145
  In addition to instance methods, you can pass a block as a task callback, and you can mix both syntaxes in your class:
@@ -164,7 +170,7 @@ end
164
170
  ## Customize Plain Ruby Class Instantiation
165
171
  Before the first task runs, Serially creates an instance of your class, on which your task callbacks are then called. By default, instances of plain ruby classes
166
172
  are created using simple `new`. If your class has a custom `initialize` method that you want to be called when creating instance of your class, it's easy to achieve. All you need to do is to implement
167
- `instance_id` method that can return any number of arguments, which will be passed as-is to 'initialize`.
173
+ `instance_id` method that can return any number of arguments, which will be passed as-is to your `initialize`.
168
174
 
169
175
  ```ruby
170
176
  class Post
@@ -229,4 +235,4 @@ Copyright (c) 2015-2016 Mike Polischuk
229
235
 
230
236
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
231
237
 
232
- [1]: https://github.com/mikemarsian/serially-demo
238
+ [1]: https://github.com/mikemarsian/serially-demo
@@ -35,6 +35,13 @@ module Serially
35
35
  @serially
36
36
  end
37
37
 
38
+ def start_batch!(instance_ids)
39
+ queue = Serially::TaskManager[self].queue
40
+ instance_ids.each do |instance_id|
41
+ Serially::Job.enqueue(self, instance_id, queue)
42
+ end
43
+ end
44
+
38
45
  def is_active_record?
39
46
  self < ActiveRecord::Base
40
47
  end
@@ -1,3 +1,3 @@
1
1
  module Serially
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serially
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Polischuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-04 00:00:00.000000000 Z
11
+ date: 2016-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque