async-job 0.4.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ffa0a39944dc1f82127f38c80719276cdfdd82ec88e646bc692eb1d911a6fec
4
- data.tar.gz: ec1c86e09371653676a74c5c3a9d2da4e4d8043ebe0bfb76080dc514ea8ab00d
3
+ metadata.gz: 6aa1dbd39e225aaa055f15ffb7976669c500ce4e6a803262356f47ad026a826b
4
+ data.tar.gz: c594059b63317a346fac7b7780ea99f633ab2f94c9bd20ede9bdd80c2b310f47
5
5
  SHA512:
6
- metadata.gz: 3b66c463d4fe746da427746b9fe22e32e47b6564884b7ab09887ef7af4c67966cd1320c06c8a5895031dc63b22e569f04c3a92a84fb10db759e9c2ae6bb06701
7
- data.tar.gz: 07360d202ae1f6860e6d63fabc55d7fa35e80f13cb58214e0282a13410b975d5b0e206ba0346cdf4a984fc5ef2f8c10d356d8229263390b696427a483a1c787f
6
+ metadata.gz: 73f4fe066ea17811d637a00592b34dc51c350287e1ffe7f73e7ae98dd3413800685804ec70b1038eca718ee353d36c41afcaf77752ed237c726aadff60545a2d
7
+ data.tar.gz: b9e0dc1720b5f4bc8eb920a265e41a8a95bcdcf3db2694fdfd358fe9a62d3752b371c680acefebf1bfb12012e50440e216139725888391580180b4dc79de059e
checksums.yaml.gz.sig CHANGED
Binary file
@@ -5,24 +5,29 @@
5
5
 
6
6
  require_relative '../../coder'
7
7
 
8
+ require 'async/idler'
9
+
8
10
  module Async
9
11
  module Job
10
12
  module Backend
11
13
  module Inline
12
14
  class Server
13
- def initialize(delegate)
15
+ def initialize(delegate, parent: nil)
14
16
  @delegate = delegate
17
+ @parent = parent || Async::Idler.new
15
18
  end
16
19
 
17
20
  def call(job)
18
21
  scheduled_at = Coder::Time(job["scheduled_at"])
19
22
 
20
- Async do
23
+ @parent.async do
21
24
  if scheduled_at
22
25
  sleep(scheduled_at - Time.now)
23
26
  end
24
27
 
25
28
  @delegate.call(job)
29
+ rescue => error
30
+ Console.error(self, error)
26
31
  end
27
32
  end
28
33
  end
@@ -73,7 +73,7 @@ module Async
73
73
  end
74
74
 
75
75
  def complete(id)
76
- Console.info(self, "Completing job: #{id}")
76
+ # Console.debug(self, "Completing job: #{id}")
77
77
  @client.evalsha(@complete, 2, @pending_key, @job_store.key, id)
78
78
  end
79
79
 
@@ -7,16 +7,17 @@ require_relative 'delayed_queue'
7
7
  require_relative 'job_store'
8
8
  require_relative 'processing_queue'
9
9
  require_relative 'ready_queue'
10
+ require_relative '../../coder'
10
11
 
11
12
  require 'securerandom'
12
- require_relative '../../coder'
13
+ require 'async/idler'
13
14
 
14
15
  module Async
15
16
  module Job
16
17
  module Backend
17
18
  module Redis
18
19
  class Server
19
- def initialize(delegate, client, prefix: 'async-job', coder: Coder::DEFAULT, resolution: 10)
20
+ def initialize(delegate, client, prefix: 'async-job', coder: Coder::DEFAULT, resolution: 10, parent: nil)
20
21
  @delegate = delegate
21
22
 
22
23
  @id = SecureRandom.uuid
@@ -31,6 +32,8 @@ module Async
31
32
  @ready_queue = ReadyQueue.new(@client, "#{@prefix}:ready")
32
33
 
33
34
  @processing_queue = ProcessingQueue.new(@client, "#{@prefix}:processing", @id, @ready_queue, @job_store)
35
+
36
+ @parent = parent || Async::Idler.new
34
37
  end
35
38
 
36
39
  def start
@@ -42,7 +45,7 @@ module Async
42
45
  @processing_queue.start
43
46
 
44
47
  while true
45
- self.dequeue
48
+ self.dequeue(@parent)
46
49
  end
47
50
  end
48
51
 
@@ -58,16 +61,21 @@ module Async
58
61
 
59
62
  protected
60
63
 
61
- def dequeue
62
- id = @processing_queue.fetch
63
- begin
64
+ def dequeue(parent)
65
+ _id = @processing_queue.fetch
66
+
67
+ parent.async do
68
+ id = _id; _id = nil
69
+
64
70
  job = @coder.load(@job_store.get(id))
65
71
  @delegate.call(job)
66
72
  @processing_queue.complete(id)
67
73
  rescue => error
68
74
  @processing_queue.retry(id)
69
- raise
75
+ Console.error(self, error)
70
76
  end
77
+ ensure
78
+ @processing_queue.retry(_id) if _id
71
79
  end
72
80
  end
73
81
  end
@@ -29,7 +29,7 @@ module Async
29
29
  end
30
30
 
31
31
  def queue(queue, *arguments, **options)
32
- # The delegate is the output side of the queue, e.g. a Queuedelegate or similar wrapper.
32
+ # The delegate is the output side of the queue, e.g. a Redis server delegate or similar wrapper.
33
33
  # The queue itself is instantiated with the delegate.
34
34
  @queue = ->(delegate){queue.new(delegate, *arguments, **options)}
35
35
  end
@@ -52,7 +52,11 @@ module Async
52
52
  end
53
53
 
54
54
  # We can now construct the queue with the delegate:
55
- producer = consumer = @queue.call(delegate)
55
+ if @queue
56
+ producer = consumer = @queue.call(delegate)
57
+ else
58
+ producer = consumer = delegate
59
+ end
56
60
 
57
61
  # We now construct the queue producer:
58
62
  @enqueue.reverse_each do |middleware|
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Async
7
7
  module Job
8
- VERSION = "0.4.2"
8
+ VERSION = "0.6.0"
9
9
  end
10
10
  end
data/license.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # MIT License
2
2
 
3
3
  Copyright, 2024, by Samuel Williams.
4
+ Copyright, 2024, by Alexey Ivanov.
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -12,6 +12,10 @@ Please see the [project documentation](https://socketry.github.io/async-job/) fo
12
12
 
13
13
  - [Redis Backend](https://socketry.github.io/async-job/guides/redis-backend/index) - This guide gives a brief overview of the implementation of the Redis backend.
14
14
 
15
+ ## See Also
16
+
17
+ - [async-job-adapter-active\_job](https://github.com/socketry/async-job-adapter-active_job) - ActiveJob adapter for `async-job`.
18
+
15
19
  ## Contributing
16
20
 
17
21
  We welcome contributions to this project.
@@ -24,8 +28,8 @@ We welcome contributions to this project.
24
28
 
25
29
  ### Developer Certificate of Origin
26
30
 
27
- This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
31
+ In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
28
32
 
29
- ### Contributor Covenant
33
+ ### Community Guidelines
30
34
 
31
- This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
35
+ This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-job
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Alexey Ivanov
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain:
@@ -37,22 +38,22 @@ cert_chain:
37
38
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
39
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
40
  -----END CERTIFICATE-----
40
- date: 2024-02-26 00:00:00.000000000 Z
41
+ date: 2024-08-02 00:00:00.000000000 Z
41
42
  dependencies:
42
43
  - !ruby/object:Gem::Dependency
43
44
  name: async
44
45
  requirement: !ruby/object:Gem::Requirement
45
46
  requirements:
46
- - - ">="
47
+ - - "~>"
47
48
  - !ruby/object:Gem::Version
48
- version: '1.0'
49
+ version: '2.9'
49
50
  type: :runtime
50
51
  prerelease: false
51
52
  version_requirements: !ruby/object:Gem::Requirement
52
53
  requirements:
53
- - - ">="
54
+ - - "~>"
54
55
  - !ruby/object:Gem::Version
55
- version: '1.0'
56
+ version: '2.9'
56
57
  - !ruby/object:Gem::Dependency
57
58
  name: async-redis
58
59
  requirement: !ruby/object:Gem::Requirement
@@ -97,6 +98,7 @@ licenses:
97
98
  - MIT
98
99
  metadata:
99
100
  documentation_uri: https://socketry.github.io/async-job/
101
+ source_code_uri: https://github.com/socketry/async-job
100
102
  post_install_message:
101
103
  rdoc_options: []
102
104
  require_paths:
@@ -105,14 +107,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
107
  requirements:
106
108
  - - ">="
107
109
  - !ruby/object:Gem::Version
108
- version: '3.0'
110
+ version: '3.1'
109
111
  required_rubygems_version: !ruby/object:Gem::Requirement
110
112
  requirements:
111
113
  - - ">="
112
114
  - !ruby/object:Gem::Version
113
115
  version: '0'
114
116
  requirements: []
115
- rubygems_version: 3.5.3
117
+ rubygems_version: 3.5.11
116
118
  signing_key:
117
119
  specification_version: 4
118
120
  summary: A asynchronous job queue for Ruby.
metadata.gz.sig CHANGED
Binary file