djwrapper 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +18 -4
- data/Rakefile +2 -2
- data/header.txt +1 -1
- data/lib/djwrapper/background_process.rb +7 -6
- data/lib/djwrapper/delayed_background_process.rb +5 -1
- data/lib/djwrapper/job.rb +40 -13
- data/lib/djwrapper.rb +6 -2
- data/test/myjob.rb +6 -1
- data/test/test_djwrapper.rb +17 -1
- data/test/test_helper.rb +9 -1
- metadata +24 -8
data/README.rdoc
CHANGED
@@ -14,14 +14,27 @@ A job class that gives you some nifty methods:
|
|
14
14
|
- log (log messages)
|
15
15
|
- time (pass a block and it will log the elapsed time)
|
16
16
|
|
17
|
+
This gem also does some basic logging for your background tasks. The logs will show up in your log/<environment>.log file with pretty colored output!
|
18
|
+
|
17
19
|
== SYNOPSIS:
|
18
20
|
|
19
21
|
class Myjob < Djwrapper::DelayedBackgroundProcess
|
20
22
|
def self.process!(params = {})
|
21
|
-
|
23
|
+
super
|
24
|
+
|
25
|
+
time do
|
22
26
|
# do stuff here ...
|
23
|
-
|
24
|
-
|
27
|
+
log("Something happened here!")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# show debug log lines?
|
32
|
+
# e.g. log("debug", :debug => true)
|
33
|
+
#
|
34
|
+
# will only be shown if verbose? if true
|
35
|
+
def self.verbose?
|
36
|
+
# default is false
|
37
|
+
true
|
25
38
|
end
|
26
39
|
end
|
27
40
|
|
@@ -33,6 +46,7 @@ A job class that gives you some nifty methods:
|
|
33
46
|
== REQUIREMENTS:
|
34
47
|
|
35
48
|
- delayed_job
|
49
|
+
- colors
|
36
50
|
|
37
51
|
== INSTALL:
|
38
52
|
|
@@ -42,7 +56,7 @@ A job class that gives you some nifty methods:
|
|
42
56
|
|
43
57
|
(The MIT License)
|
44
58
|
|
45
|
-
Copyright (c)
|
59
|
+
Copyright (c) 2013 Commander Johnson <commanderjohnson@gmail.com>
|
46
60
|
|
47
61
|
Permission is hereby granted, free of charge, to any person obtaining
|
48
62
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
@@ -12,8 +12,8 @@ Hoe.plugin :newgem
|
|
12
12
|
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
13
|
$hoe = Hoe.spec 'djwrapper' do
|
14
14
|
self.developer 'Commander Johnson', 'commanderjohnson@gmail.com'
|
15
|
-
self.rubyforge_name = self.name
|
16
|
-
self.extra_deps = [[ 'delayed_job', ">= 0
|
15
|
+
self.rubyforge_name = self.name
|
16
|
+
self.extra_deps = [[ 'delayed_job', ">= 0" ], [ 'colors', ">= 0" ]]
|
17
17
|
end
|
18
18
|
|
19
19
|
require 'newgem/tasks'
|
data/header.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
################################################################################
|
2
2
|
# Written by Commander Johnson <commanderjohnson@gmail.com>
|
3
|
-
# Year:
|
3
|
+
# Year: 2013
|
4
4
|
# Licensed under the MIT license
|
5
5
|
################################################################################
|
6
6
|
|
@@ -2,10 +2,16 @@
|
|
2
2
|
# -- begin header --
|
3
3
|
################################################################################
|
4
4
|
# Written by Commander Johnson <commanderjohnson@gmail.com>
|
5
|
-
# Year:
|
5
|
+
# Year: 2013
|
6
6
|
# Licensed under the MIT license
|
7
7
|
################################################################################
|
8
8
|
|
9
|
+
|
10
|
+
#JstWnnaHveFuN08: do you think i should call a guy friend and talk to him about my problems? or will he not care?
|
11
|
+
#Thilo: Here's how it works: if a guy helps you with your problems, you're obligated to give him a blowjob.
|
12
|
+
#JstWnnaHveFuN08: lol thanks that cheered me up
|
13
|
+
#Thilo: No problem. That'll be one blowjob please.
|
14
|
+
|
9
15
|
# -- end header --
|
10
16
|
module Djwrapper
|
11
17
|
class BackgroundProcess
|
@@ -41,11 +47,6 @@ module Djwrapper
|
|
41
47
|
log("Finished in #{delta} seconds.")
|
42
48
|
end
|
43
49
|
|
44
|
-
# make verbose false by default.
|
45
|
-
# use log("message") to log messages that are not really important
|
46
|
-
# use log("message", :important => true) to log important messages.
|
47
|
-
#
|
48
|
-
# if verbose is set to true, all messages will be logged.
|
49
50
|
def self.verbose?
|
50
51
|
false
|
51
52
|
end
|
@@ -2,10 +2,14 @@
|
|
2
2
|
# -- begin header --
|
3
3
|
################################################################################
|
4
4
|
# Written by Commander Johnson <commanderjohnson@gmail.com>
|
5
|
-
# Year:
|
5
|
+
# Year: 2013
|
6
6
|
# Licensed under the MIT license
|
7
7
|
################################################################################
|
8
8
|
|
9
|
+
|
10
|
+
#<Patrician|Away> what does your robot do, sam
|
11
|
+
#<bovril> it collects data about the surrounding environment, then discards it and drives into walls
|
12
|
+
|
9
13
|
# -- end header --
|
10
14
|
module Djwrapper
|
11
15
|
class DelayedBackgroundProcess < BackgroundProcess
|
data/lib/djwrapper/job.rb
CHANGED
@@ -2,53 +2,80 @@
|
|
2
2
|
# -- begin header --
|
3
3
|
################################################################################
|
4
4
|
# Written by Commander Johnson <commanderjohnson@gmail.com>
|
5
|
-
# Year:
|
5
|
+
# Year: 2013
|
6
6
|
# Licensed under the MIT license
|
7
7
|
################################################################################
|
8
8
|
|
9
|
+
|
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.
|
25
|
+
|
9
26
|
# -- end header --
|
10
27
|
module Djwrapper
|
11
28
|
class Job < Struct.new(:class_name, :params, :method_name)
|
12
29
|
##############################################################################
|
13
30
|
# class methods
|
14
31
|
##############################################################################
|
15
|
-
|
32
|
+
|
16
33
|
##############################################################################
|
17
34
|
# constructor
|
18
35
|
##############################################################################
|
19
|
-
|
36
|
+
|
20
37
|
##############################################################################
|
21
38
|
# instance methods
|
22
39
|
##############################################################################
|
23
|
-
|
40
|
+
|
24
41
|
def perform
|
25
42
|
# default parameters
|
26
43
|
params ||= {}
|
27
44
|
method_name ||= "process!"
|
28
|
-
|
45
|
+
|
29
46
|
ret = false
|
30
|
-
|
47
|
+
|
31
48
|
#Rails.logger.info("Djwrapper::Job: starting 'perform' method ...")
|
32
|
-
|
49
|
+
|
33
50
|
raise "class_name must be a String!" unless class_name.is_a?(String)
|
34
51
|
raise "params must be a Hash!" unless params.is_a?(Hash)
|
35
|
-
|
52
|
+
|
36
53
|
klazz = eval(class_name)
|
37
|
-
|
54
|
+
|
38
55
|
# u kidding me? :'(
|
39
56
|
#>> Djwrapper::DelayedBackgroundProcess.is_a?(Djwrapper::DelayedBackgroundProcess)
|
40
57
|
#=> false
|
41
58
|
|
42
59
|
#raise "class #{klazz.to_s} must be subclass of ::Djwrapper::BackgroundProcess" unless klazz.is_a?(Djwrapper::BackgroundProcess)
|
43
|
-
|
60
|
+
|
44
61
|
#Rails.logger.info("Djwrapper::Job: Calling '#{method_name}' method on class #{klazz.to_s} with parameters: #{params}")
|
45
62
|
|
46
63
|
# dont wrap this in a begin rescue end block.
|
47
64
|
# it wont crash since it's a delayed job, and otherwise we could not ask DJ what the error was.
|
48
|
-
|
49
|
-
|
65
|
+
# oh wait, we can just wrap it, and then re-raise the exception.
|
66
|
+
ret = nil
|
67
|
+
begin
|
68
|
+
ret = klazz.send(method_name, params)
|
69
|
+
klazz.send("log", "Job done".green)
|
70
|
+
rescue => e
|
71
|
+
klazz.send("log", "Job failed :(".red)
|
72
|
+
raise e
|
73
|
+
end
|
74
|
+
# return code.
|
75
|
+
klazz.send("log", "Job returned: #{ret.inspect}")
|
76
|
+
|
50
77
|
#Rails.logger.info("Djwrapper::Job: done with 'perform' method.")
|
51
|
-
|
78
|
+
|
52
79
|
ret
|
53
80
|
end
|
54
81
|
end
|
data/lib/djwrapper.rb
CHANGED
@@ -2,10 +2,14 @@
|
|
2
2
|
# -- begin header --
|
3
3
|
################################################################################
|
4
4
|
# Written by Commander Johnson <commanderjohnson@gmail.com>
|
5
|
-
# Year:
|
5
|
+
# Year: 2013
|
6
6
|
# Licensed under the MIT license
|
7
7
|
################################################################################
|
8
8
|
|
9
|
+
|
10
|
+
#<BombScare> i beat the internet
|
11
|
+
#<BombScare> the end guy is hard
|
12
|
+
|
9
13
|
# -- end header --
|
10
14
|
$:.unshift(File.dirname(__FILE__)) unless
|
11
15
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
@@ -15,5 +19,5 @@ require 'djwrapper/background_process'
|
|
15
19
|
require 'djwrapper/delayed_background_process'
|
16
20
|
|
17
21
|
module Djwrapper
|
18
|
-
VERSION = '0.0.
|
22
|
+
VERSION = '0.0.9'
|
19
23
|
end
|
data/test/myjob.rb
CHANGED
@@ -2,10 +2,15 @@
|
|
2
2
|
# -- begin header --
|
3
3
|
################################################################################
|
4
4
|
# Written by Commander Johnson <commanderjohnson@gmail.com>
|
5
|
-
# Year:
|
5
|
+
# Year: 2013
|
6
6
|
# Licensed under the MIT license
|
7
7
|
################################################################################
|
8
8
|
|
9
|
+
|
10
|
+
#<Sabdo> on one of those speech-to-text programs my friend ripped ass onto the mic.
|
11
|
+
#<Sabdo> and it typed out "France"
|
12
|
+
#<Sabdo> we were like, wtf?
|
13
|
+
|
9
14
|
# -- end header --
|
10
15
|
class Myjob < Djwrapper::DelayedBackgroundProcess
|
11
16
|
def self.process!(params = {})
|
data/test/test_djwrapper.rb
CHANGED
@@ -2,10 +2,26 @@
|
|
2
2
|
# -- begin header --
|
3
3
|
################################################################################
|
4
4
|
# Written by Commander Johnson <commanderjohnson@gmail.com>
|
5
|
-
# Year:
|
5
|
+
# Year: 2013
|
6
6
|
# Licensed under the MIT license
|
7
7
|
################################################################################
|
8
8
|
|
9
|
+
|
10
|
+
#random girl: hey!
|
11
|
+
#me: ...hi?
|
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
|
24
|
+
|
9
25
|
# -- end header --
|
10
26
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
11
27
|
|
data/test/test_helper.rb
CHANGED
@@ -2,10 +2,18 @@
|
|
2
2
|
# -- begin header --
|
3
3
|
################################################################################
|
4
4
|
# Written by Commander Johnson <commanderjohnson@gmail.com>
|
5
|
-
# Year:
|
5
|
+
# Year: 2013
|
6
6
|
# Licensed under the MIT license
|
7
7
|
################################################################################
|
8
8
|
|
9
|
+
|
10
|
+
#<drmason> there was this one time I was wanking to porn...
|
11
|
+
#<drmason> ... I kept a javascript tutorial open in another window so my parents didn't start wondering why I was always on the desktop with no windows showing
|
12
|
+
#<drmason> so I'm just about to splurge when I suddenly hear my dad coming up the stairs
|
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"
|
16
|
+
|
9
17
|
# -- end header --
|
10
18
|
require 'stringio'
|
11
19
|
require 'test/unit'
|
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.9
|
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-02-
|
12
|
+
date: 2013-02-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: delayed_job
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0
|
21
|
+
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,23 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: colors
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: rdoc
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +82,7 @@ dependencies:
|
|
66
82
|
requirements:
|
67
83
|
- - ~>
|
68
84
|
- !ruby/object:Gem::Version
|
69
|
-
version: '3.
|
85
|
+
version: '3.5'
|
70
86
|
type: :development
|
71
87
|
prerelease: false
|
72
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +90,7 @@ dependencies:
|
|
74
90
|
requirements:
|
75
91
|
- - ~>
|
76
92
|
- !ruby/object:Gem::Version
|
77
|
-
version: '3.
|
93
|
+
version: '3.5'
|
78
94
|
description: Wrapper gem for Delayed Job.
|
79
95
|
email:
|
80
96
|
- commanderjohnson@gmail.com
|
@@ -126,10 +142,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
142
|
version: '0'
|
127
143
|
requirements: []
|
128
144
|
rubyforge_project: djwrapper
|
129
|
-
rubygems_version: 1.8.
|
145
|
+
rubygems_version: 1.8.24
|
130
146
|
signing_key:
|
131
147
|
specification_version: 3
|
132
148
|
summary: Wrapper gem for Delayed Job.
|
133
149
|
test_files:
|
134
|
-
- test/test_djwrapper.rb
|
135
150
|
- test/test_helper.rb
|
151
|
+
- test/test_djwrapper.rb
|