Skip to content

Commit

Permalink
Include next_run_args for background worker.
Browse files Browse the repository at this point in the history
  • Loading branch information
Renato Mascarenhas committed Aug 29, 2016
1 parent afdadc2 commit fdc7fc9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
19 changes: 10 additions & 9 deletions config/mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@
entity BackgroundWorker
repository BackgroundWorkerRepository

attribute :id, Integer
attribute :host_id, Integer
attribute :supplier_id, Integer
attribute :next_run_at, Time
attribute :interval, Integer
attribute :type, String
attribute :status, String
attribute :created_at, Time
attribute :updated_at, Time
attribute :id, Integer
attribute :host_id, Integer
attribute :supplier_id, Integer
attribute :next_run_at, Time
attribute :next_run_args, Concierge::PGJSON
attribute :interval, Integer
attribute :type, String
attribute :status, String
attribute :created_at, Time
attribute :updated_at, Time
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Hanami::Model.migration do
change do
alter_table :background_workers do
add_column :next_run_args, JSON, null: false, default: Sequel.pg_json({})
end
end
end
28 changes: 15 additions & 13 deletions lib/concierge/entities/background_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
#
# Attributes
#
# +id+ - the ID of the the record on the database, automatically generated.
# +host_id+ - a foreign key to the +hosts+ table, indicating which host
# the background worker is associated with.
# +supplier_id+ - a foreign key to the +suppliers+ table, indicating which supplier
# the background worker is associated with. Either this column or
# +host_id+ must be set.
# +next_run_at+ - a timestamp that indicates when the background worker should be
# invoked next.
# +interval+ - how often (in seconds), the background worker should be invoked.
# +type+ - the type of synchronisation performed by the background worker.
# +status+ - the status of the worker, which indicate its activity at a given moment.
# +id+ - the ID of the the record on the database, automatically generated.
# +host_id+ - a foreign key to the +hosts+ table, indicating which host
# the background worker is associated with.
# +supplier_id+ - a foreign key to the +suppliers+ table, indicating which supplier
# the background worker is associated with. Either this column or
# +host_id+ must be set.
# +next_run_at+ - a timestamp that indicates when the background worker should be
# invoked next.
# +next_run_args+ - arguments to be passed to the worker implementation (listening on the
# proper event) on the next run.
# +interval+ - how often (in seconds), the background worker should be invoked.
# +type+ - the type of synchronisation performed by the background worker.
# +status+ - the status of the worker, which indicate its activity at a given moment.
class BackgroundWorker
include Hanami::Entity

Expand All @@ -39,8 +41,8 @@ class BackgroundWorker
# be rescheduled.
STATUSES = %w(idle running)

attributes :id, :host_id, :supplier_id, :next_run_at, :interval, :type, :status,
:created_at, :updated_at
attributes :id, :host_id, :supplier_id, :next_run_at, :next_run_args, :interval,
:type, :status, :created_at, :updated_at

def running?
status == "running"
Expand Down

0 comments on commit fdc7fc9

Please sign in to comment.