after_commit_queue 0.0.1 → 0.0.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.
- data/README.md +72 -0
- data/Rakefile +8 -3
- data/lib/after_commit_queue/version.rb +1 -1
- data/test/after_commit_queue_test.rb +1 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +44 -0
- data/test/dummy/log/test.log +30 -0
- metadata +7 -7
- data/README.rdoc +0 -3
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# after_commit_queue
|
2
|
+
---
|
3
|
+
|
4
|
+
Rails plugin which allows to run callbacks after database transaction is committed.
|
5
|
+
|
6
|
+
### What problem does it solve ?
|
7
|
+
|
8
|
+
When using [state_machine](https://github.com/pluginaweek/state_machine) it's hard to run a callback on event after the transaction is committed.
|
9
|
+
|
10
|
+
after_commit_queue plugin addresses this problem.
|
11
|
+
|
12
|
+
### Installation
|
13
|
+
|
14
|
+
Add this to your Gemfile and run ```bundle install```
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'after_commit_queue'
|
18
|
+
```
|
19
|
+
|
20
|
+
### Usage
|
21
|
+
|
22
|
+
Include AfterCommitQueue module in your ActiveRecord model and you're ready to go.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
class Server < ActiveRecord::Base
|
26
|
+
attr_accessor :started, :stopped
|
27
|
+
|
28
|
+
# include plugin
|
29
|
+
include AfterCommitQueue
|
30
|
+
|
31
|
+
state_machine :state, :initial => :pending do
|
32
|
+
after_transition :pending => :running, :do => :schedule_start
|
33
|
+
after_transition :running => :turned_off, :do => :schedule_stop
|
34
|
+
event(:start) { transition :pending => :running }
|
35
|
+
event(:stop) { transition :running => :turned_off }
|
36
|
+
end
|
37
|
+
|
38
|
+
def schedule_start
|
39
|
+
# Adds method to be run after transaction is committed
|
40
|
+
run_after_commit(:start_server)
|
41
|
+
end
|
42
|
+
|
43
|
+
def schedule_stop
|
44
|
+
run_after_commit(:stop_server)
|
45
|
+
end
|
46
|
+
|
47
|
+
def start_server; @started = true end
|
48
|
+
def stop_server; @stopped = true end
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
### Contributions
|
53
|
+
|
54
|
+
To fetch & test the library for development, do:
|
55
|
+
|
56
|
+
$ git clone https://github.com/Ragnarson/after_commit_queue
|
57
|
+
$ cd after_commit_queue
|
58
|
+
$ bundle
|
59
|
+
|
60
|
+
#### Running tests
|
61
|
+
|
62
|
+
# Before each test run, the database will be created and migrated automatically
|
63
|
+
$ bundle exec rake test
|
64
|
+
|
65
|
+
If you want to contribute, please:
|
66
|
+
|
67
|
+
* Fork the project.
|
68
|
+
* Make your feature addition or bug fix.
|
69
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
70
|
+
* Send me a pull request on Github.
|
71
|
+
|
72
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
CHANGED
@@ -21,9 +21,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
21
21
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
24
|
Bundler::GemHelper.install_tasks
|
28
25
|
|
29
26
|
require 'rake/testtask'
|
@@ -37,3 +34,11 @@ end
|
|
37
34
|
|
38
35
|
|
39
36
|
task :default => :test
|
37
|
+
|
38
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
39
|
+
load 'rails/tasks/engine.rake'
|
40
|
+
|
41
|
+
Rake::Task['test'].enhance ['app:db:drop']
|
42
|
+
Rake::Task['test'].enhance ['app:db:create']
|
43
|
+
Rake::Task['test'].enhance ['app:db:migrate']
|
44
|
+
Rake::Task['test'].enhance ['app:db:test:prepare']
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -29,3 +29,47 @@ Connecting to database specified by database.yml
|
|
29
29
|
[1m[35m (1.2ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
30
30
|
[1m[36m (0.1ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
31
31
|
[1m[35m (1.1ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('20120622135717')
|
32
|
+
Connecting to database specified by database.yml
|
33
|
+
[1m[36m (0.1ms)[0m [1mselect sqlite_version(*)[0m
|
34
|
+
[1m[35m (1.3ms)[0m CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
|
35
|
+
[1m[36m (0.0ms)[0m [1mPRAGMA index_list("schema_migrations")[0m
|
36
|
+
[1m[35m (1.1ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
37
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
38
|
+
Migrating to CreateServers (20120622135717)
|
39
|
+
[1m[35m (0.0ms)[0m begin transaction
|
40
|
+
[1m[36m (0.3ms)[0m [1mCREATE TABLE "servers" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "state" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) [0m
|
41
|
+
[1m[35m (0.1ms)[0m INSERT INTO "schema_migrations" ("version") VALUES ('20120622135717')
|
42
|
+
[1m[36m (1.1ms)[0m [1mcommit transaction[0m
|
43
|
+
[1m[35m (0.3ms)[0m select sqlite_version(*)
|
44
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
45
|
+
[1m[35m (0.0ms)[0m PRAGMA index_list("servers")
|
46
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
47
|
+
[1m[35m (0.2ms)[0m select sqlite_version(*)
|
48
|
+
[1m[36m (1.2ms)[0m [1mCREATE TABLE "servers" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "state" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) [0m
|
49
|
+
[1m[35m (1.2ms)[0m CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
|
50
|
+
[1m[36m (0.0ms)[0m [1mPRAGMA index_list("schema_migrations")[0m
|
51
|
+
[1m[35m (0.9ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
52
|
+
[1m[36m (0.1ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
53
|
+
[1m[35m (1.2ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('20120622135717')
|
54
|
+
Connecting to database specified by database.yml
|
55
|
+
[1m[36m (0.1ms)[0m [1mselect sqlite_version(*)[0m
|
56
|
+
[1m[35m (2.5ms)[0m CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
|
57
|
+
[1m[36m (0.0ms)[0m [1mPRAGMA index_list("schema_migrations")[0m
|
58
|
+
[1m[35m (1.3ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
59
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
60
|
+
Migrating to CreateServers (20120622135717)
|
61
|
+
[1m[35m (0.0ms)[0m begin transaction
|
62
|
+
[1m[36m (0.3ms)[0m [1mCREATE TABLE "servers" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "state" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) [0m
|
63
|
+
[1m[35m (0.1ms)[0m INSERT INTO "schema_migrations" ("version") VALUES ('20120622135717')
|
64
|
+
[1m[36m (1.2ms)[0m [1mcommit transaction[0m
|
65
|
+
[1m[35m (0.2ms)[0m select sqlite_version(*)
|
66
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
67
|
+
[1m[35m (0.0ms)[0m PRAGMA index_list("servers")
|
68
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
69
|
+
[1m[35m (0.2ms)[0m select sqlite_version(*)
|
70
|
+
[1m[36m (1.3ms)[0m [1mCREATE TABLE "servers" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "state" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) [0m
|
71
|
+
[1m[35m (1.0ms)[0m CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
|
72
|
+
[1m[36m (0.0ms)[0m [1mPRAGMA index_list("schema_migrations")[0m
|
73
|
+
[1m[35m (1.1ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
74
|
+
[1m[36m (0.1ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
75
|
+
[1m[35m (1.0ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('20120622135717')
|
data/test/dummy/log/test.log
CHANGED
@@ -270,3 +270,33 @@ Connecting to database specified by database.yml
|
|
270
270
|
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
271
271
|
[1m[35mSQL (0.5ms)[0m INSERT INTO "servers" ("created_at", "state", "updated_at") VALUES (?, ?, ?) [["created_at", Fri, 22 Jun 2012 15:35:43 UTC +00:00], ["state", "running"], ["updated_at", Fri, 22 Jun 2012 15:35:43 UTC +00:00]]
|
272
272
|
[1m[36m (0.7ms)[0m [1mcommit transaction[0m
|
273
|
+
Connecting to database specified by database.yml
|
274
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
275
|
+
[1m[35mSQL (5.1ms)[0m INSERT INTO "servers" ("created_at", "state", "updated_at") VALUES (?, ?, ?) [["created_at", Fri, 22 Jun 2012 15:58:05 UTC +00:00], ["state", "running"], ["updated_at", Fri, 22 Jun 2012 15:58:05 UTC +00:00]]
|
276
|
+
[1m[36m (0.8ms)[0m [1mcommit transaction[0m
|
277
|
+
[1m[35m (0.1ms)[0m begin transaction
|
278
|
+
[1m[36m (0.3ms)[0m [1mUPDATE "servers" SET "state" = 'turned_off', "updated_at" = '2012-06-22 15:58:05.778522' WHERE "servers"."id" = 25[0m
|
279
|
+
[1m[35m (0.7ms)[0m commit transaction
|
280
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
281
|
+
[1m[35mSQL (0.5ms)[0m INSERT INTO "servers" ("created_at", "state", "updated_at") VALUES (?, ?, ?) [["created_at", Fri, 22 Jun 2012 15:58:05 UTC +00:00], ["state", "running"], ["updated_at", Fri, 22 Jun 2012 15:58:05 UTC +00:00]]
|
282
|
+
[1m[36m (0.7ms)[0m [1mcommit transaction[0m
|
283
|
+
Connecting to database specified by database.yml
|
284
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
285
|
+
[1m[35mSQL (5.1ms)[0m INSERT INTO "servers" ("created_at", "state", "updated_at") VALUES (?, ?, ?) [["created_at", Wed, 18 Jul 2012 21:11:10 UTC +00:00], ["state", "running"], ["updated_at", Wed, 18 Jul 2012 21:11:10 UTC +00:00]]
|
286
|
+
[1m[36m (1.1ms)[0m [1mcommit transaction[0m
|
287
|
+
[1m[35m (0.0ms)[0m begin transaction
|
288
|
+
[1m[36m (0.2ms)[0m [1mUPDATE "servers" SET "state" = 'turned_off', "updated_at" = '2012-07-18 21:11:10.161801' WHERE "servers"."id" = 1[0m
|
289
|
+
[1m[35m (0.6ms)[0m commit transaction
|
290
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
291
|
+
[1m[35mSQL (0.4ms)[0m INSERT INTO "servers" ("created_at", "state", "updated_at") VALUES (?, ?, ?) [["created_at", Wed, 18 Jul 2012 21:11:10 UTC +00:00], ["state", "running"], ["updated_at", Wed, 18 Jul 2012 21:11:10 UTC +00:00]]
|
292
|
+
[1m[36m (0.6ms)[0m [1mcommit transaction[0m
|
293
|
+
Connecting to database specified by database.yml
|
294
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
295
|
+
[1m[35mSQL (2.6ms)[0m INSERT INTO "servers" ("created_at", "state", "updated_at") VALUES (?, ?, ?) [["created_at", Wed, 18 Jul 2012 21:16:29 UTC +00:00], ["state", "running"], ["updated_at", Wed, 18 Jul 2012 21:16:29 UTC +00:00]]
|
296
|
+
[1m[36m (1.1ms)[0m [1mcommit transaction[0m
|
297
|
+
[1m[35m (0.0ms)[0m begin transaction
|
298
|
+
[1m[36m (0.2ms)[0m [1mUPDATE "servers" SET "state" = 'turned_off', "updated_at" = '2012-07-18 21:16:29.689270' WHERE "servers"."id" = 1[0m
|
299
|
+
[1m[35m (1.1ms)[0m commit transaction
|
300
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
301
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "servers" ("created_at", "state", "updated_at") VALUES (?, ?, ?) [["created_at", Wed, 18 Jul 2012 21:16:29 UTC +00:00], ["state", "running"], ["updated_at", Wed, 18 Jul 2012 21:16:29 UTC +00:00]]
|
302
|
+
[1m[36m (0.9ms)[0m [1mcommit transaction[0m
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: after_commit_queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-07-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 3.
|
22
|
+
version: '3.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: 3.
|
30
|
+
version: '3.0'
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: sqlite3
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,7 +56,7 @@ files:
|
|
56
56
|
- lib/tasks/after_commit_queue_tasks.rake
|
57
57
|
- MIT-LICENSE
|
58
58
|
- Rakefile
|
59
|
-
- README.
|
59
|
+
- README.md
|
60
60
|
- test/after_commit_queue_test.rb
|
61
61
|
- test/dummy/app/assets/javascripts/application.js
|
62
62
|
- test/dummy/app/assets/stylesheets/application.css
|
@@ -110,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
segments:
|
112
112
|
- 0
|
113
|
-
hash: -
|
113
|
+
hash: -2163612595833260696
|
114
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
115
|
none: false
|
116
116
|
requirements:
|
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
segments:
|
121
121
|
- 0
|
122
|
-
hash: -
|
122
|
+
hash: -2163612595833260696
|
123
123
|
requirements: []
|
124
124
|
rubyforge_project:
|
125
125
|
rubygems_version: 1.8.24
|
data/README.rdoc
DELETED