delayed_job_es 0.1.5 → 0.1.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c88fb7a192a3120949ca0ed3632f4baaf9feb2f8
4
- data.tar.gz: aa663a7f03dafebbf16b08639212c96cfe0915c1
3
+ metadata.gz: 4fd671a6bb8f35764c38d1acd3c7f2b29e3eea26
4
+ data.tar.gz: 9655192518c56711d3a5f06f318a9e3dbd7f5dcd
5
5
  SHA512:
6
- metadata.gz: 8cbadc3e99718b31ac0f761b9f08212af85db8711fbb31310633c2c5a530a504fb0bf67ce07ebdce630580d4adfc507674550f3f543df342b4a97924f8fd60a4
7
- data.tar.gz: 5ade19e9c69b8937e4bb6264c60f4b382089c8ca9fac6fc7ae9d8a55e6119ab2d2060028f652982720f680f0238249dc92c4257922c52947b729122507c21aac
6
+ metadata.gz: d7863a77e1da57fe74f39731dc069feb2f42a981607bb3e9a86d0a4f10be88dcbea05f017c7500795dea1b25f52db4359972b199d01a89cef925d53b2ae13b3e
7
+ data.tar.gz: 84b681c6cd05ffc38665f095a9ccfb718a9fbcbf72a2dcf9d140728fa05f20bd03d18f7a36678a2c82ee8eb2e076d7b9bea54f39ab55ab39d41f0109073be8f4
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # DelayedJobEs
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/delayed_job_es`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Delayed Job Backend adapter for ElasticSearch.
4
+
5
+
6
+ The gem uses the 'elasticsearch-transport' and 'elasticsearch-api' as dependencies.
7
+
8
+ It has no other dependencies, and should be easy to integrate into any ruby based project that uses elasticsearch in any form.
4
9
 
5
- TODO: Delete this and the text above, and describe your gem
6
10
 
7
11
  ## Installation
8
12
 
@@ -14,7 +18,7 @@ gem 'delayed_job_es'
14
18
 
15
19
  And then execute:
16
20
 
17
- $ bundle
21
+ $ bundle install
18
22
 
19
23
  Or install it yourself as:
20
24
 
@@ -22,13 +26,68 @@ Or install it yourself as:
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ ### Job Class
30
+
31
+ Create a Job Class in the app/jobs folder :
32
+
33
+ ```
34
+ class BackgroundJob < ActiveJob::Base
35
+
36
+ queue_as :default
37
+
38
+ ## Specify the queue adapter as delayed_job_es
39
+ self.queue_adapter = :delayed_job
40
+
41
+ self.logger = Logger.new(nil) if Rails.env.test?
42
+
43
+ rescue_from(StandardError) do |exception|
44
+ puts exception.message
45
+ puts exception.backtrace.join("\n")
46
+ end
47
+
48
+ def perform(args)
49
+ ## process job here.
50
+ end
51
+
52
+ end
53
+ ```
54
+
55
+ ### Es Indexes
56
+
57
+ Create required ES Indexes:
58
+
59
+
60
+ ```ruby
61
+ # in the rails console, (you only need to do this once)
62
+ DelayedJob::Backend::Es::Job.create_indices
63
+ ```
64
+
65
+ ### Job Daemon
66
+
67
+ Open a terminal window, navigate to your project and run :
68
+
69
+ $ bundle exec rake jobs:work
70
+
71
+ This will run a job daemon(standard DelayedJob).
72
+
73
+
74
+ ### Queue a Job
75
+
76
+ To queue a job, from anywhere using the job class above run (you can try this in the rails console, in another window):
77
+
78
+
79
+ ```ruby
80
+ BackgroundJob.perform_later({"hello" => "world"})
81
+ ```
82
+
83
+ If you look in the jobs daemon window, you will see the job getting processed.
84
+
85
+
86
+
26
87
 
27
88
  ## Development
28
89
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
90
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
91
 
33
92
  ## Contributing
34
93
 
@@ -9,6 +9,7 @@ module Delayed
9
9
  module Es
10
10
  class Job
11
11
  attr_accessor :id
12
+ attr_accessor :version
12
13
  attr_accessor :priority
13
14
  attr_accessor :attempts
14
15
  attr_accessor :handler
@@ -335,18 +336,20 @@ module Delayed
335
336
 
336
337
  search_response = get_client.search :index => INDEX_NAME, :type => DOCUMENT_TYPE,
337
338
  :body => {
339
+ version: true,
338
340
  size: limit,
339
341
  sort: sort,
340
342
  query: query
341
343
  }
342
344
 
343
345
 
344
- #puts "search_response is"
345
- #puts search_response["hits"]["hits"]
346
+ puts "search_response is"
347
+ puts search_response["hits"]["hits"]
346
348
  ## it would return the first hit.
347
349
  search_response["hits"]["hits"].map{|c|
348
350
  k = new(c["_source"])
349
351
  k.id = c["_id"]
352
+ k.version = c["_version"]
350
353
  k
351
354
  }
352
355
 
@@ -362,21 +365,38 @@ module Delayed
362
365
  :lang => "painless",
363
366
  :params => {
364
367
  :locked_at => self.class.db_time_now.strftime("%Y-%m-%d %H:%M:%S"),
365
- :locked_by => worker
368
+ :locked_by => worker,
369
+ :version => self.version
366
370
  },
367
371
  :source => '''
368
- ctx._source.locked_at = params.locked_at;
369
- ctx._source.locked_by = params.locked_by;
372
+ if(ctx._version == params.version){
373
+ ctx._source.locked_at = params.locked_at;
374
+ ctx._source.locked_by = params.locked_by;
375
+ }
376
+ else{
377
+ ctx.op = "none";
378
+ }
370
379
  '''
371
380
  }
381
+
382
+ puts "Script is"
383
+ puts JSON.pretty_generate(script)
384
+
385
+
372
386
  #begin
373
387
  response = self.class.get_client.update(index: INDEX_NAME, type: DOCUMENT_TYPE, id: self.id.to_s, body: {
374
388
  :script => script,
375
389
  :scripted_upsert => false,
376
390
  :upsert => {}
377
391
  })
378
-
379
- self
392
+
393
+ ## if this returns no-op chec,
394
+ puts "lock response:"
395
+ puts response.to_s
396
+
397
+
398
+ return response["result"] == "updated"
399
+
380
400
  end
381
401
 
382
402
  def self.db_time_now
@@ -1,3 +1,3 @@
1
1
  module DelayedJobEs
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_job_es
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Great Manta
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-17 00:00:00.000000000 Z
11
+ date: 2020-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler