djwrapper 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -0
- data/lib/djwrapper/background_process.rb +29 -4
- data/lib/djwrapper/delayed_background_process.rb +7 -2
- data/lib/djwrapper/job.rb +19 -16
- data/lib/djwrapper.rb +16 -3
- data/test/myjob.rb +1 -3
- data/test/test_djwrapper.rb +31 -41
- data/test/test_helper.rb +3 -6
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -43,6 +43,19 @@ This gem also does some basic logging for your background tasks. The logs will s
|
|
43
43
|
# Create a background job.
|
44
44
|
Myjob.enqueue
|
45
45
|
|
46
|
+
== SIGNAL HANDLING:
|
47
|
+
|
48
|
+
If you have a job that runs for a very long time, it may be killed at some point. You then want it to exit gracefully so you don't have any errors in your database. Add this piece of code to the start (or end) of your big loop so the loop will at least finish its iteration before the process gets killed.
|
49
|
+
|
50
|
+
The signals that are caught by default are TERM and INT. TERM is sent by the 'daemons' gem (script/delayed_job stop), and INT corresponds to Ctrl-C in your terminal.
|
51
|
+
|
52
|
+
if $_djwrapper_interrupted
|
53
|
+
log("Got interrupted. Doing graceful exit ...")
|
54
|
+
|
55
|
+
return true
|
56
|
+
end
|
57
|
+
|
58
|
+
|
46
59
|
== REQUIREMENTS:
|
47
60
|
|
48
61
|
- delayed_job
|
@@ -7,10 +7,14 @@
|
|
7
7
|
################################################################################
|
8
8
|
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
#*** Topic in #doghouse is 'Our hearts are extended to the 17 victims of the recent internet fraud'
|
11
|
+
#* Anubis has joined #doghouse
|
12
|
+
#<Anubis> what fraud?
|
13
|
+
#<Kadmium> You haven't heard about it?
|
14
|
+
#<Anubis> no?
|
15
|
+
#<Kadmium> You can read the full story at http://www.tubgirl.com
|
16
|
+
#<Anubis> omg wtf!
|
17
|
+
#*** Kadmium changes topic to 'Our hearts are extended to the 18 victims of the recent internet fraud'
|
14
18
|
|
15
19
|
# -- end header --
|
16
20
|
module Djwrapper
|
@@ -19,6 +23,27 @@ module Djwrapper
|
|
19
23
|
# class methods
|
20
24
|
##############################################################################
|
21
25
|
|
26
|
+
# --------------------------------------------------------
|
27
|
+
|
28
|
+
$_djwrapper_interrupted = nil
|
29
|
+
|
30
|
+
def self.trap_handler
|
31
|
+
Proc.new do |sig|
|
32
|
+
log("Caught #{sig} ...")
|
33
|
+
$_djwrapper_interrupted = sig
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.signals
|
38
|
+
[ "INT", "TERM" ]
|
39
|
+
end
|
40
|
+
|
41
|
+
self.signals.each do |sig|
|
42
|
+
trap(sig, trap_handler)
|
43
|
+
end
|
44
|
+
|
45
|
+
# --------------------------------------------------------
|
46
|
+
|
22
47
|
def self.process!(params = {})
|
23
48
|
# Add code here that should be processed by every BackgroundProcess
|
24
49
|
# right before it starts executing its own process! method.
|
@@ -7,8 +7,13 @@
|
|
7
7
|
################################################################################
|
8
8
|
|
9
9
|
|
10
|
-
#<
|
11
|
-
#<
|
10
|
+
#<Stormrider> I should bomb something
|
11
|
+
#<Stormrider> ...and it's off the cuff remarks like that that are the reason I don't log chats
|
12
|
+
#<Stormrider> Just in case the FBI ever needs anything on me
|
13
|
+
#<Elzie_Ann> I'm sure they can just get it from someone who DOES log chats.
|
14
|
+
#*** FBI has joined #gamecubecafe
|
15
|
+
#<FBI> We saw it anyway.
|
16
|
+
#*** FBI has quit IRC (Quit: )
|
12
17
|
|
13
18
|
# -- end header --
|
14
19
|
|
data/lib/djwrapper/job.rb
CHANGED
@@ -7,21 +7,23 @@
|
|
7
7
|
################################################################################
|
8
8
|
|
9
9
|
|
10
|
-
#<
|
11
|
-
#<
|
12
|
-
#<
|
13
|
-
#<
|
14
|
-
#<
|
15
|
-
#<
|
16
|
-
#<
|
17
|
-
#<
|
18
|
-
#<
|
19
|
-
#<
|
20
|
-
#<
|
21
|
-
#<
|
22
|
-
#<
|
23
|
-
|
24
|
-
#<
|
10
|
+
#<Cthon98> hey, if you type in your pw, it will show as stars
|
11
|
+
#<Cthon98> ********* see!
|
12
|
+
#<AzureDiamond> hunter2
|
13
|
+
#<AzureDiamond> doesnt look like stars to me
|
14
|
+
#<Cthon98> <AzureDiamond> *******
|
15
|
+
#<Cthon98> thats what I see
|
16
|
+
#<AzureDiamond> oh, really?
|
17
|
+
#<Cthon98> Absolutely
|
18
|
+
#<AzureDiamond> you can go hunter2 my hunter2-ing hunter2
|
19
|
+
#<AzureDiamond> haha, does that look funny to you?
|
20
|
+
#<Cthon98> lol, yes. See, when YOU type hunter2, it shows to us as *******
|
21
|
+
#<AzureDiamond> thats neat, I didnt know IRC did that
|
22
|
+
#<Cthon98> yep, no matter how many times you type hunter2, it will show to us as *******
|
23
|
+
#<AzureDiamond> awesome!
|
24
|
+
#<AzureDiamond> wait, how do you know my pw?
|
25
|
+
#<Cthon98> er, I just copy pasted YOUR ******'s and it appears to YOU as hunter2 cause its your pw
|
26
|
+
#<AzureDiamond> oh, ok.
|
25
27
|
|
26
28
|
# -- end header --
|
27
29
|
module Djwrapper
|
@@ -63,10 +65,11 @@ module Djwrapper
|
|
63
65
|
# dont wrap this in a begin rescue end block.
|
64
66
|
# it wont crash since it's a delayed job, and otherwise we could not ask DJ what the error was.
|
65
67
|
# oh wait, we can just wrap it, and then re-raise the exception.
|
68
|
+
# NICE DUDE
|
66
69
|
ret = nil
|
67
70
|
begin
|
68
71
|
ret = klazz.send(method_name, params)
|
69
|
-
klazz.send("log", "Job done")
|
72
|
+
klazz.send("log", "Job done.")
|
70
73
|
rescue => e
|
71
74
|
klazz.send("log", "Job failed :(")
|
72
75
|
raise e
|
data/lib/djwrapper.rb
CHANGED
@@ -7,8 +7,21 @@
|
|
7
7
|
################################################################################
|
8
8
|
|
9
9
|
|
10
|
-
#<
|
11
|
-
#<
|
10
|
+
#<Tedward> so there's this pimp right. he's collecting money from his three ho's.
|
11
|
+
#<Tedward> he goes to the first ho and asks for his $100. she says, "But I only owe you $50!"
|
12
|
+
#<Tedward> he slaps her and says, "don't correct me, bitch!"
|
13
|
+
#<Tedward> he asks the next ho for $150. she says, "But I only owe you $100!"
|
14
|
+
#<Tedward> he slaps her and says, "don't correct me, bitch!"
|
15
|
+
#<Tedward> now he goes to his third ho.
|
16
|
+
#<Tedward> he asks for $200. "but I only owe you $150!"
|
17
|
+
#<Tedward> he slaps her and says, "don't correct me, bitch!"
|
18
|
+
#<Tedward> next he visits the fourth ho.
|
19
|
+
#<Tedward> he asks her for his $250.
|
20
|
+
#<Thy_Dungeonman> hold on, wait a sec
|
21
|
+
#<Tedward> what?
|
22
|
+
#<Thy_Dungeonman> you said three ho's, not four. idioth.
|
23
|
+
#*Tedward slaps Thy_Dungeonman
|
24
|
+
#<Tedward> Don't correct me, bitch.
|
12
25
|
|
13
26
|
# -- end header --
|
14
27
|
$:.unshift(File.dirname(__FILE__)) unless
|
@@ -19,5 +32,5 @@ require 'djwrapper/background_process'
|
|
19
32
|
require 'djwrapper/delayed_background_process'
|
20
33
|
|
21
34
|
module Djwrapper
|
22
|
-
VERSION = '0.0.
|
35
|
+
VERSION = '0.0.11'
|
23
36
|
end
|
data/test/myjob.rb
CHANGED
@@ -7,9 +7,7 @@
|
|
7
7
|
################################################################################
|
8
8
|
|
9
9
|
|
10
|
-
#<
|
11
|
-
#<Sabdo> and it typed out "France"
|
12
|
-
#<Sabdo> we were like, wtf?
|
10
|
+
#<scirDSL> I hated going to weddings. All the grandmas would poke me saying "You're next". They stopped that when I started doing it to them at funerals.
|
13
11
|
|
14
12
|
# -- end header --
|
15
13
|
class Myjob < Djwrapper::DelayedBackgroundProcess
|
data/test/test_djwrapper.rb
CHANGED
@@ -7,46 +7,36 @@
|
|
7
7
|
################################################################################
|
8
8
|
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
#me: who is this?
|
13
|
-
#random girl: Jessica, I saw u on myspace
|
14
|
-
#random girl: ur hot
|
15
|
-
#me: thanks
|
16
|
-
#random girl: np
|
17
|
-
#me: this girl keeps bugging me, but I don't want to talk to her
|
18
|
-
#me: what should I do?
|
19
|
-
#random girl: make up sum excuse, like ur mom is kickin u off or sumthing
|
20
|
-
#me: oh alright
|
21
|
-
#me: I have to go
|
22
|
-
#me: my mom is kicking me off
|
23
|
-
#me: bye
|
10
|
+
#<DigiGnome> Real life should have a fucking search function, or something.
|
11
|
+
#<DigiGnome> I need my socks.
|
24
12
|
|
25
13
|
# -- end header --
|
26
|
-
|
27
|
-
|
28
|
-
require '
|
29
|
-
|
30
|
-
require '
|
31
|
-
|
32
|
-
require '
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
14
|
+
# Not using this anymore. Tests have been extracted into a separate Rails project, djwrapper_test
|
15
|
+
|
16
|
+
#require File.dirname(__FILE__) + '/test_helper.rb'
|
17
|
+
#
|
18
|
+
#require 'rubygems'
|
19
|
+
#require 'delayed_job'
|
20
|
+
#require 'rails'
|
21
|
+
#
|
22
|
+
#require 'test/myjob'
|
23
|
+
#
|
24
|
+
#class TestDjwrapper < Test::Unit::TestCase
|
25
|
+
# def setup
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# def test_process
|
29
|
+
# Myjob.process!
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# def test_enqueue
|
33
|
+
# Myjob.enqueue
|
34
|
+
#
|
35
|
+
# c = Delayed::Job.count
|
36
|
+
# assert_equal 1, c
|
37
|
+
# # +_+ #
|
38
|
+
# r = Delayed::Worker.new.work_off
|
39
|
+
#
|
40
|
+
# assert_equal [1, 0], r
|
41
|
+
# end
|
42
|
+
#end
|
data/test/test_helper.rb
CHANGED
@@ -7,12 +7,9 @@
|
|
7
7
|
################################################################################
|
8
8
|
|
9
9
|
|
10
|
-
#<
|
11
|
-
#<
|
12
|
-
#<
|
13
|
-
#<drmason> alt-tabbed to the other window and tried to pull my boxers up... computer stalled JUST THEN as my dad was opening the door
|
14
|
-
#<drmason> I just stood up and was like "fuck... dad this honestly isn't what it looks like"
|
15
|
-
#<drmason> and he glanced at the screen and said "I sure hope so because it looks like you're masturbating to a fucking javascript tutorial"
|
10
|
+
#<mage> what should I give sister for unzipping?
|
11
|
+
#<Kevyn> Um. Ten bucks?
|
12
|
+
#<mage> no I mean like, WinZip?
|
16
13
|
|
17
14
|
# -- end header --
|
18
15
|
require 'stringio'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: djwrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: delayed_job
|
@@ -131,5 +131,5 @@ signing_key:
|
|
131
131
|
specification_version: 3
|
132
132
|
summary: Wrapper gem for Delayed Job.
|
133
133
|
test_files:
|
134
|
-
- test/test_helper.rb
|
135
134
|
- test/test_djwrapper.rb
|
135
|
+
- test/test_helper.rb
|