### Setup Services for Testing Source: https://github.com/activesphere/exq-scheduler/blob/master/README.md This command uses Docker Compose to set up and start the necessary services (like Redis) required for running Exq Scheduler tests. ```bash $ docker-compose up ``` -------------------------------- ### Start Exq Scheduler Demo Project Source: https://github.com/activesphere/exq-scheduler/blob/master/README.md This command starts the Exq Scheduler demo project. Ensure you have navigated to the demo directory before running the script. ```bash > cd demo > ./start_demo.sh ``` -------------------------------- ### Install Demo Project Dependencies Source: https://github.com/activesphere/exq-scheduler/blob/master/README.md These commands show how to install dependencies for the Exq Scheduler demo project. It involves navigating to the demo directory, fetching Mix dependencies, and installing Ruby gems for the Sidekiq UI. ```bash > cd demo > mix deps.get > cd sidekiq-ui > bundle install ``` -------------------------------- ### Install Project Dependencies for Testing Source: https://github.com/activesphere/exq-scheduler/blob/master/README.md This command installs the Mix dependencies for the Exq Scheduler project, which is a prerequisite before running the tests. ```bash $ mix deps.get ``` -------------------------------- ### Install Sidekiq for Testing Source: https://github.com/activesphere/exq-scheduler/blob/master/README.md This command installs Sidekiq and its dependencies, which is required for running Exq Scheduler tests. It specifies the exact versions of bundler and Ruby to ensure compatibility. ```bash $ (cd sidekiq && gem install bundler:1.16.1 && bundle install) ``` -------------------------------- ### Start Exq Scheduler in Elixir Application Source: https://context7.com/activesphere/exq-scheduler/llms.txt Demonstrates how to start the ExqScheduler supervisor within your Elixir application's Application module. It configures schedules, storage, and Redis connection. ```elixir defmodule MyApp.Application do use Application def start(_type, _args) do children = [ {ExqScheduler, [ name: MyScheduler, schedules: [ my_job: %{ cron: "*/5 * * * *", class: "MyWorker" } ], storage: [exq_namespace: "exq"], redis: [ name: ExqScheduler.Redis.Client, child_spec: {Redix, [host: "localhost", name: ExqScheduler.Redis.Client]} ] }]} ] Supervisor.start_link(children, strategy: :one_for_one) end end ``` -------------------------------- ### Complete Worker Example for ExqScheduler Source: https://context7.com/activesphere/exq-scheduler/llms.txt Provides a comprehensive example of a worker module compatible with Exq and ExqScheduler. It showcases different `perform` function signatures to handle varying arguments and metadata, along with configuration in `config.exs`. ```elixir # lib/workers/report_worker.ex defmodule ReportWorker do @moduledoc """ Worker for generating scheduled reports. Compatible with Exq job processor. """ def perform do # Called when no args configured generate_report("default") end def perform(report_type) do # Called with single arg generate_report(report_type) end def perform(report_type, metadata) when is_map(metadata) do # Called when include_metadata: true scheduled_at = Map.get(metadata, "scheduled_at") IO.puts("Report scheduled for: #{scheduled_at}") generate_report(report_type) end defp generate_report(type) do IO.puts("Generating #{type} report at #{DateTime.utc_now()}") # Report generation logic :ok end end # config/config.exs config :exq_scheduler, :schedules, morning_report: %{ description: "Daily morning report", cron: "0 8 * * *", class: "ReportWorker", args: ["morning"], include_metadata: true, queue: "reports" } ``` -------------------------------- ### Full Application Configuration for Exq Scheduler Source: https://context7.com/activesphere/exq-scheduler/llms.txt Presents a comprehensive configuration example for Exq Scheduler in `config.exs`, covering global settings like `missed_jobs_window` and `time_zone`, Redis storage namespace, and detailed Redis connection parameters. ```elixir # config/config.exs import Config # Global settings config :exq_scheduler, missed_jobs_window: 3 * 60 * 60 * 1000, # 3 hours in milliseconds time_zone: "UTC", start_on_application: true # Redis storage namespace config :exq_scheduler, :storage, exq_namespace: "exq" # Redis connection config :exq_scheduler, :redis, name: ExqScheduler.Redis.Client, child_spec: { Redix, [ host: System.get_env("REDIS_HOST", "127.0.0.1"), port: String.to_integer(System.get_env("REDIS_PORT", "6379")), database: 0, name: ExqScheduler.Redis.Client ] } ``` -------------------------------- ### Disable Exq Scheduler Auto-Start Source: https://github.com/activesphere/exq-scheduler/blob/master/README.md This Elixir configuration disables the automatic starting of Exq Scheduler when the application boots. Set `start_on_application` to `false` to manually control when the scheduler starts. ```elixir config :exq_scheduler, start_on_application: false ``` -------------------------------- ### Immediately Enqueue Job - ExqScheduler.enqueue_now/2 Source: https://context7.com/activesphere/exq-scheduler/llms.txt Demonstrates how to trigger a scheduled job immediately using ExqScheduler.enqueue_now/2, bypassing the regular cron schedule. This is useful for manual triggers or testing purposes. Includes an example within a controller. ```elixir # Immediately trigger a scheduled job :ok = ExqScheduler.enqueue_now(MyScheduler, :daily_report) # Useful for testing or manual triggers defmodule AdminController do def trigger_report(conn, %{"schedule" => schedule_name}) do schedule = String.to_existing_atom(schedule_name) case ExqScheduler.enqueue_now(MyScheduler, schedule) do :ok -> json(conn, %{status: "Job enqueued"}) {:error, reason} -> json(conn, %{status: "error", message: reason}) end end end ``` -------------------------------- ### Run Exq Scheduler Tests Source: https://github.com/activesphere/exq-scheduler/blob/master/README.md This command executes the test suite for the Exq Scheduler project using Mix. ```bash $ mix test ``` -------------------------------- ### Define Basic Schedules with Cron Syntax (Elixir) Source: https://context7.com/activesphere/exq-scheduler/llms.txt This Elixir configuration demonstrates how to define basic scheduled jobs using cron syntax. Each schedule requires a name, cron expression, worker class, and optionally a queue and arguments. ```elixir config :exq_scheduler, :schedules, daily_report: %{ description: "Generate daily report at midnight", cron: "0 0 * * *", class: "DailyReportWorker", queue: "default", args: [] }, hourly_cleanup: %{ cron: "0 * * * *", class: "CleanupWorker", queue: "maintenance" } ``` -------------------------------- ### Enable/Disable Schedules at Runtime - ExqScheduler.enable/2, ExqScheduler.disable/2 Source: https://context7.com/activesphere/exq-scheduler/llms.txt Illustrates how to dynamically enable or disable specific schedules using ExqScheduler.enable/2 and ExqScheduler.disable/2 without requiring an application restart. It also shows error handling for non-existent schedules. ```elixir # Disable a schedule :ok = ExqScheduler.disable(MyScheduler, :daily_report) # Enable a schedule :ok = ExqScheduler.enable(MyScheduler, :daily_report) # Handle errors for non-existent schedules case ExqScheduler.disable(MyScheduler, :nonexistent) do :ok -> IO.puts("Schedule disabled") {:error, reason} -> IO.puts("Error: #{reason}") end ``` -------------------------------- ### Schedule Jobs with Arguments (Elixir) Source: https://context7.com/activesphere/exq-scheduler/llms.txt This Elixir configuration shows how to schedule jobs that require arguments. These arguments are passed to the worker's `perform` function, allowing for dynamic job execution based on specific parameters. ```elixir config :exq_scheduler, :schedules, process_orders: %{ description: "Process pending orders every 15 minutes", cron: "*/15 * * * *", class: "OrderProcessor", queue: "orders", args: ["pending", 100], retry: 5 } # Worker module (processed by Exq) defmodule OrderProcessor do def perform(status, limit) do # status = "pending", limit = 100 Orders.process_by_status(status, limit) end end ``` -------------------------------- ### Retrieve Configured Schedules - ExqScheduler.schedules/1 Source: https://context7.com/activesphere/exq-scheduler/llms.txt Shows how to retrieve a list of all configured schedules along with their status, last run time, and next scheduled run time using ExqScheduler.schedules/1. It returns a list of maps containing schedule information. ```elixir # Get schedules from a named scheduler schedules = ExqScheduler.schedules(MyScheduler) # Returns list of schedule info maps: # [ # %{ # cron: "0 * * * *", # schedule: %ExqScheduler.Schedule{ # name: :hourly_job, # description: "Hourly task", # cron: %Crontab.CronExpression{...}, # timezone: "UTC", # job: %ExqScheduler.Schedule.Job{class: "HourlyWorker", ...} # }, # last_run: ~U[2024-01-15 14:00:00Z], # next_run: ~U[2024-01-15 15:00:00Z] # }, # ... # ] Enum.each(schedules, fn info -> IO.puts("#{info.schedule.name}: next run at #{info.next_run}") end) ``` -------------------------------- ### Configure Exq Scheduler Redis Client Source: https://github.com/activesphere/exq-scheduler/blob/master/README.md This Elixir configuration defines the Redis client for Exq Scheduler. It specifies the client's name and its child specification for the supervisor tree, including host, port, and the client name. The `name` in `child_spec` must match the `:name` configuration. ```elixir config :exq_scheduler, :redis, name: ExqScheduler.Redis.Client, child_spec: {Redix, [host: "127.0.0.1", port: 6379, name: ExqScheduler.Redis.Client]} ``` -------------------------------- ### Configure Redis Connection for Exq Scheduler (Elixir) Source: https://context7.com/activesphere/exq-scheduler/llms.txt This Elixir configuration sets up the Redis connection details that ExqScheduler will use for storing schedule states and enqueuing jobs. It specifies connection parameters like host, port, database, and client name. ```elixir config :exq_scheduler, :redis, name: ExqScheduler.Redis.Client, child_spec: { Redix, [ host: "127.0.0.1", port: 6379, database: 0, name: ExqScheduler.Redis.Client, backoff_max: 1000, backoff_initial: 1000 ] } ``` -------------------------------- ### Schedule Jobs with Metadata (Elixir) Source: https://context7.com/activesphere/exq-scheduler/llms.txt This Elixir configuration illustrates scheduling jobs that include execution metadata, such as the scheduled time. This metadata is passed as the last argument to the worker's `perform` function, useful for tracking and auditing. ```elixir config :exq_scheduler, :schedules, analytics_job: %{ description: "Run analytics every hour with execution metadata", cron: "0 * * * *", class: "AnalyticsWorker", queue: "analytics", args: ["daily_stats"], include_metadata: true } # Worker receives metadata as last argument defmodule AnalyticsWorker do def perform(report_type, metadata) do # metadata = %{"scheduled_at" => 1527750039.080837} scheduled_time = metadata["scheduled_at"] Analytics.generate_report(report_type, scheduled_time) end end ``` -------------------------------- ### Configure Exq Scheduler Miscellaneous Settings Source: https://github.com/activesphere/exq-scheduler/blob/master/README.md This Elixir configuration sets miscellaneous options for Exq Scheduler, including the window for scheduling missed jobs and the default time zone. The `missed_jobs_window` should be greater than 3 hours to handle daylight saving time properly. ```elixir config :exq_scheduler, missed_jobs_window: 3 * 60 * 60 * 1000, time_zone: "Asia/Kolkata" ``` -------------------------------- ### Add Exq Scheduler Dependency Source: https://github.com/activesphere/exq-scheduler/blob/master/README.md This snippet shows how to add the Exq Scheduler as a dependency in your Elixir project's `mix.exs` file. It specifies the package name and the version constraint. ```elixir defp deps do [{:exq_scheduler, "~> x.x.x"}] end ``` -------------------------------- ### Configure Exq Scheduler Storage Source: https://github.com/activesphere/exq-scheduler/blob/master/README.md This Elixir configuration sets the Redis namespace used by Exq Scheduler for storing internal metadata. Ensure the `exq_namespace` matches your Exq configuration. ```elixir config :exq_scheduler, :storage, exq_namespace: "exq" # exq redis namespace ``` -------------------------------- ### Configure Global Timezone and Missed Jobs Window (Elixir) Source: https://context7.com/activesphere/exq-scheduler/llms.txt This Elixir configuration sets a default timezone for all schedules that do not specify one and defines a window for recovering missed jobs. The missed jobs window is specified in milliseconds. ```elixir config :exq_scheduler, # Default timezone for schedules without explicit timezone time_zone: "America/Los_Angeles", # Recover missed jobs from last 3 hours (in milliseconds) missed_jobs_window: 3 * 60 * 60 * 1000 ``` -------------------------------- ### Configure Timezone-Specific Schedules (Elixir) Source: https://context7.com/activesphere/exq-scheduler/llms.txt This Elixir configuration shows how to define schedules that run in specific timezones. The timezone is appended to the cron expression, allowing for precise scheduling across different geographical locations. ```elixir config :exq_scheduler, :schedules, tokyo_morning: %{ description: "Run at 9 AM Tokyo time", cron: "0 9 * * * Asia/Tokyo", class: "TokyoWorker", queue: "default" }, new_york_evening: %{ description: "Run at 6 PM New York time", cron: "0 18 * * * America/New_York", class: "NewYorkWorker", queue: "default" } ``` -------------------------------- ### Define Exq Scheduler Schedules Source: https://github.com/activesphere/exq-scheduler/blob/master/README.md This Elixir configuration defines various job schedules for Exq Scheduler. Each schedule includes a cron expression, the worker class name, and optional parameters like arguments, retry settings, and metadata inclusion. The `cron` and `class` parameters are required. ```elixir config :exq_scheduler, :schedules, signup_report: %{ description: "Send the list of newly signed up users to admin", cron: "0 * * * *", class: "SignUpReportWorker", include_metadata: true, args: [], queue: "default" }, login_report: %{ cron: "0 * * * *", class: "LoginReportWorker" } ``` -------------------------------- ### Define Elixir Exq Scheduler Cron Jobs Source: https://context7.com/activesphere/exq-scheduler/llms.txt Defines various cron schedules for the Exq Scheduler in Elixir. Each schedule includes a cron expression, worker class, and optional arguments, queue, retry settings, and timezone. ```elixir config :exq_scheduler, :schedules, # Every minute job heartbeat: %{ description: "System heartbeat check", cron: "* * * * *", class: "HeartbeatWorker", queue: "critical" }, # Hourly job with args sync_data: %{ description: "Sync external data hourly", cron: "0 * * * *", class: "DataSyncWorker", args: ["external_api"], queue: "default", retry: 3 }, # Daily job with timezone daily_digest: %{ description: "Send daily digest at 9 AM EST", cron: "0 9 * * * America/New_York", class: "DigestWorker", queue: "emails", include_metadata: true }, # Weekly job weekly_cleanup: %{ description: "Clean up old records every Sunday at midnight", cron: "0 0 * * 0", class: "CleanupWorker", args: [30], # days to keep queue: "maintenance" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.