8000 GitHub - fsateler/activejob-status: A simple monitoring status for ActiveJob
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fsateler/activejob-status

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ActiveJob::Status

Simple monitoring status for ActiveJob, independent of your queuing backend or cache storage.

gem 'activejob-status'

Configuration

Cache Store

By default, ActiveJob::Status use the Rails.cache to store data. You can use any compatible ActiveSupport::Cache::Store you want (memory, memcache, redis, ..) or any storage responding to read/write/delete

Note : In Rails 5, Rails.cache defaults to ActiveSupport::Cache::NullStore which will result in empty status. Setting a cache store for ActiveJob::Status is therefore mandatory.

To set your own store:

# config/initializers/activejob_status.rb
# By default
ActiveJob::Status.store = Rails.cache

# Set another storage
ActiveJob::Status.store = ActiveSupport::Cache::MemoryStore.new

# Use the ActiveSupport#lookup_store syntax
ActiveJob::Status.store = :redis_store

Expiration time

Because ActiveJob::Status relies on cache store, all statuses come with an expiration item. It's set to 1 hour by default.

To set a longer expiration:

# config/initializers/activejob_status.rb
ActiveJob::Status.options = { expires_in: 30.days.to_i }

Usage

Include the ActiveJob::Status module in your jobs.

class MyJob < ActiveJob::Base
  include ActiveJob::Status
end

The module introduces two methods:

  • status to directly read/update status
  • progress to implement a progress status
class MyJob < ActiveJob::Base
  include ActiveJob::Status

  def perform
    status.update(foo: false)

    progress.total = 1000

    1000.time do |i|
      progress.increment
    end

    status.update(foo: true)
  end
end

Check the status of a job

job = MyJob.perform_later
status = ActiveJob::Status.get(job)
# => { status: :queued }

You can also use the job_id

status = ActiveJob::Status.get('d11b64e6-8631-4118-ae76-e19376769171')
# => { status: :queued }

Follow the progression of your job

status
# => { status: :working, progress: 100, total: 1000, foo: false }

status.working?
# => true

status.progress
# => 0.1

status[:foo]
# => false

until it's completed

status
# => { status: :completed, progress: 1000, total: 1000, foo: true }

status.completed?
# => true

status.progress
# => 1

status[:foo]
# => true

Within a controller

def status
  status = ActiveJob::Status.get(params[:job])
  render json: status.to_json
end

Contributing

  1. Don't hesitate to submit your feature/idea/fix in issues
  2. Fork the repository
  3. Create your feature branch
  4. Create a pull request

Tests

Not yet provided.

License & credits

Copyright (c) 2019 Savater Sebastien.
See LICENSE for further details.

Contributors:

About

A simple monitoring status for ActiveJob

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%
0