Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for returning scheduled job date time #187

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/qless/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Job < BaseJob
attr_reader :jid, :expires_at, :state, :queue_name, :worker_name, :failure
attr_reader :klass_name, :tracked, :dependencies, :dependents
attr_reader :original_retries, :retries_left, :raw_queue_history
attr_reader :state_changed
attr_reader :state_changed, :scheduleddate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scheduleddate should be scheduled_date by convention

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. The entire way scheduleddate is calculated and presented needs to be adjusted. Have been using it in prod and finding a few gaps and expected features that were missed first round

attr_accessor :data, :priority, :tags
alias_method(:state_changed?, :state_changed)

Expand Down Expand Up @@ -98,7 +98,8 @@ def self.build(client, klass, attributes = {})
'failure' => {},
'history' => [],
'dependencies' => [],
'dependents' => []
'dependents' => [],
'scheduleddate' => 0
}
attributes = defaults.merge(Qless.stringify_hash_keys(attributes))
attributes['data'] = JSON.dump(attributes['data'])
Expand Down Expand Up @@ -129,6 +130,7 @@ def initialize(client, atts)
@original_retries = atts.fetch('retries')
@retries_left = atts.fetch('remaining')
@raw_queue_history = atts.fetch('history')
@scheduleddate = atts.fetch('scheduleddate')

# This is a silly side-effect of Lua doing JSON parsing
@tags = [] if @tags == {}
Expand All @@ -143,6 +145,10 @@ def priority=(priority)
@priority = priority if @client.call('priority', @jid, priority)
end

def scheduledate
Time.at(@scheduleddate)
end

def [](key)
@data[key]
end
Expand Down