Repository navigation
Expand file tree
/
Copy pathenqueue
More file actions
executable file
·62 lines (50 loc) · 1.35 KB
/
Copy pathenqueue
File metadata and controls
executable file
·62 lines (50 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
7536
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env ruby
# Push a job onto the Delayed Job queue without booting the Rails stack
# Perfect for calling via cron.
#
# Use like this:
#
# ./script/enqueue <JobClassName>
# ./script/enqueue Background::ImportJobs
require 'erb'
require 'yaml'
ENV["RAILS_ENV"] ||= "development"
DATABASE_CONFIG = File.expand_path("../../config/database.yml", __FILE__)
def psql
raise "Missing database.yml" unless File.exists?(DATABASE_CONFIG)
file = File.read(DATABASE_CONFIG)
erb = ERB.new(file).result
env = ENV["RAILS_ENV"]
config = YAML.load(erb)[env]
raise "Missing config for #{env} environment" unless config
"psql".tap do |s|
s << " --quiet"
s << " --host #{config['host']}" if config['host']
s << " --user #{config['username']}" if config['username']
s << " --port #{config['port']}" if config['port']
s << " #{config['database']}"
end
end
def enqueue_delayed_job(handler, priority=nil)
time = Time.now.utc.strftime("%Y-%m-%d %H:%M:%S")
priority ||= 50
sql = <<-SQL
INSERT INTO delayed_jobs (
handler,
created_at,
updated_at,
run_at,
priority
) VALUES (
'--- !ruby/object:#{handler} {}\n',
'#{time}',
'#{time}',
'#{time}',
#{priority}
);
SQL
IO.popen(psql, "w") do |io|
io.write sql
end
end
enqueue_delayed_job ARGV[0], ARGV[1]