Class: ResetDemoUserWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/reset_demo_user_worker.rb

Overview

Background worker to create the demo user (if it doesn't exist yet) and reset its configuration, folders and subscribed feeds.

The credentials for the demo user are:

This is a Sidekiq worker

Instance Method Summary collapse

Constructor Details

#initializeResetDemoUserWorker

Store config values in instance variables, for DRYer code.


22
23
24
25
26
27
28
29
30
# File 'app/workers/reset_demo_user_worker.rb', line 22

def initialize
  @demo_email = Feedbunch::Application.config.demo_email
  @demo_password = Feedbunch::Application.config.demo_password
  @demo_name = Feedbunch::Application.config.demo_name
  @demo_locale = I18n.default_locale
  @demo_timezone = Feedbunch::Application.config.time_zone
  @demo_quick_reading = Feedbunch::Application.config.demo_quick_reading
  @demo_open_all_entries = Feedbunch::Application.config.demo_open_all_entries
end

Instance Method Details

#performObject

Create the demo user if it still doesn't exist. Reset its configuration, folders and subscribed feeds.


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/workers/reset_demo_user_worker.rb', line 35

def perform
  Rails.logger.debug 'Resetting demo user'

  unless Feedbunch::Application.config.demo_enabled
    Rails.logger.debug 'Demo user is disabled'
    # If the demo user is disabled in the configuration, just destroy it if it exists and do nothing else.
    destroy_demo_user
    return
  end

  demo_user = create_demo_user
  reset_demo_config demo_user
  reset_job_states demo_user
  reset_feeds_and_folders demo_user
end