{"id":26524908,"url":"https://github.com/podemos-info/active_job_reporter","last_synced_at":"2025-03-21T14:24:16.612Z","repository":{"id":59150312,"uuid":"110832205","full_name":"podemos-info/active_job_reporter","owner":"podemos-info","description":"Monitoring and reporting for ActiveJob","archived":false,"fork":false,"pushed_at":"2017-11-17T22:36:57.000Z","size":72,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-30T04:55:35.913Z","etag":null,"topics":["activejob","gem","monitor","rails","ruby","status"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/podemos-info.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-15T12:44:20.000Z","updated_at":"2023-09-08T17:32:38.000Z","dependencies_parsed_at":"2022-09-13T11:00:32.873Z","dependency_job_id":null,"html_url":"https://github.com/podemos-info/active_job_reporter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/podemos-info%2Factive_job_reporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/podemos-info%2Factive_job_reporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/podemos-info%2Factive_job_reporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/podemos-info%2Factive_job_reporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/podemos-info","download_url":"https://codeload.github.com/podemos-info/active_job_reporter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244579166,"owners_count":20475620,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activejob","gem","monitor","rails","ruby","status"],"created_at":"2025-03-21T14:24:15.967Z","updated_at":"2025-03-21T14:24:16.587Z","avatar_url":"https://github.com/podemos-info.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Active Job Reporter\nMonitoring and reporting for ActiveJob.\n\n[![Gem](https://img.shields.io/gem/v/active_job_reporter.svg)](https://rubygems.org/gems/active_job_reporter)\n[![Travis](https://img.shields.io/travis/podemos-info/active_job_reporter/master.svg)](https://travis-ci.org/podemos-info/active_job_reporter)\n[![Codecov](https://img.shields.io/codecov/c/github/podemos-info/active_job_reporter.svg)](https://codecov.io/gh/podemos-info/active_job_reporter)\n\n## Features\n* Minimalistic approach to ActiveJob monitoring, database based to avoid additional dependencies.\n* Filter jobs by status (`enqueued`, `running` or `finished`), user, resource or result (`ok`, `error` or custom).\n* Messages log by job.\n* Automatic basic exception handling during errors.\n* Allows to override built-in Job model.\n\n## Installation\n1. Add this line to your application's Gemfile:\n\n```ruby\ngem 'active_job_reporter'\n```\n\n2. Update bundle\n\n```bash\n$ bundle\n```\n\n3. Run installer \n\nAdd `jobs`, `job_objects` and `job_messages` tables to your database and an initializer file for configuration:\n\n```bash\n$ bundle exec rails generate active_job_reporter:install\n$ bundle exec rake db:migrate\n```\n\n## Usage\n\n1. Add `ReportableJob` concern to your jobs. You can add to `ApplicationJob` to avoid adding to every job. Jobs will be tracked automatically.\n\n```ruby\ninclude ActiveJobReporter::ReportableJob\n```\n\n2. Define `current_user` method in your jobs to relate them to users. Use `arguments` variable to retrieve `perform` call arguments. Using keyword arguments with the same name would allow you to define at `ApplicationJob`.\n\n```ruby\ndef current_user\n  arguments.first\u0026.fetch(:admin_user, nil)\nend\n```\n\n3. Define `related_objects` method in your jobs to relate them to other application records.\n\n```ruby\ndef related_objects\n  [\n    arguments.first\u0026.fetch(:order, nil), \n    *arguments.first\u0026.fetch(:items, [])\n  ].compact\nend\n```\n\n4. Add log messages and result code inside your jobs `perform` methods. `log` method allows to specify type of message and complex messages (stored as JSON in database). Use `self.result` to store the result of the job (won't be saved until the end of the process). If not specified, result will be `:ok` or `:error`, when the `perform` method raises an exception.\n\n```ruby\n  def perform(**params)\n    if has_issues?\n      log :issues, raw: \"raw test message\"\n      self.result = :issues\n    end\n\n    if params[:raise]\n      a = 1 / 0\n    end\n\n    log :user, key: \"test.user_message.#{result}\", params: { user_id: 1, number: 12 }\n  end\n```\n\n5. Application models related to jobs can use the `HasJobs` concern to simplify access to them.\n\n```ruby\nclass Resource \u003c ApplicationRecord\n  include ActiveJobReporter::HasJobs\nend\n```\n\nThen, access to jobs can be made from `jobs` association method.\n\n```ruby\n2.4.1 :001 \u003e Resource.first.jobs.count\n =\u003e 1\n2.4.1 :002 \u003e Resource.first.jobs.running.count\n =\u003e 0\n```\n\n6. If an application `Job` model is needed (to extend it or avoid using a qualified name), it can be defined using the `JobConcern` concern and specifying the class name in the initializer file.\n\n```ruby\n# in app/models/job.rb\nclass Job \u003c ActiveRecord::Base\n  include ActiveJobReporter::JobConcern\nend\n\n# in config/initializers/active_job_reporter.rb\nActiveJobReporter.configure do |config|\n  ...\n\n  # The class name for jobs\n  config.job_class_name = \"Job\"\n\n  ...\nend\n```\n\n## Changelog\n\n#### 0.1.2\n\n* Fixes to `JobConcern`.\n* Tests fixes.\n\n#### 0.1.1\n\n* Fixed deprecated use of class instead of class name in `belongs_to`.\n\n#### 0.1.0\n\n* First version.\n\n## Contributing\nIssues and PRs are welcomed.\n\n## License\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpodemos-info%2Factive_job_reporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpodemos-info%2Factive_job_reporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpodemos-info%2Factive_job_reporter/lists"}