Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a MOSQUITO_REDIS_URL Env Variable by default #39

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1,17 +1,19 @@
name: mosquito
version: 0.5.0
version: 0.6.0

This comment has been minimized.

Copy link
@robacarp

authors:
- robacarp

crystal: 0.29.0
crystal: 0.31.0

This comment has been minimized.

Copy link
@robacarp

license: MIT

dependencies:
redis:
github: stefanwille/crystal-redis
version: ~> 2.1.1
habitat:
github: luckyframework/habitat

development_dependencies:
minitest:
@@ -1,3 +1,5 @@
require "habitat"

module Mosquito
alias Model = Granite::Base
alias Id = Int64 | Int32
@@ -46,5 +48,17 @@ module Mosquito
def self.log(*messages)
logger.log(Logger::Severity::INFO, messages.join(" "))
end

Habitat.create do
setting redis_url : String

# Optionally add examples to settings that appear in error messages
# when the value is not set.
#
# Use `String#dump` when you want the example to be wrapped in quotes
setting redis_url : String, example: "redis://localhost:6379"

This comment has been minimized.

Copy link
@robacarp

robacarp Nov 20, 2019

Owner

Should this be the default value as well?

end

Habitat.raise_if_missing_settings!
end
end
@@ -40,9 +40,9 @@ module Mosquito
simplified_type = type.resolve
end

method_suffix = simplified_type.stringify.underscore.gsub(/::/,"__").id
method_suffix = simplified_type.stringify.underscore.gsub(/::/, "__").id

{ name: name, value: value, type: type, simplified_type: simplified_type, method_suffix: method_suffix }
{name: name, value: value, type: type, simplified_type: simplified_type, method_suffix: method_suffix}
end
%}

@@ -75,13 +75,13 @@ module Mosquito
end

def initialize({{
parsed_parameters.map do |parameter|
assignment = "@#{parameter["name"]}"
assignment = assignment + " : #{parameter["type"]}" if parameter["type"]
assignment = assignment + " = #{parameter["value"]}" if parameter["value"]
assignment
end.join(", ").id
}})
parsed_parameters.map do |parameter|
assignment = "@#{parameter["name"]}"
assignment = assignment + " : #{parameter["type"]}" if parameter["type"]
assignment = assignment + " = #{parameter["value"]}" if parameter["value"]
assignment
end.join(", ").id
}})

This comment has been minimized.

Copy link
@robacarp

robacarp Nov 20, 2019

Owner

I'm sure this got pulled in by some automatic save, but unless any of these changes are functional they should be left out, please 😁

end

def vars_from(config : Hash(String, String))
@@ -32,7 +32,9 @@ module Mosquito
end

def initialize
if url = ENV["REDIS_URL"]?
if url = ENV["MOSQUITO_REDIS_URL"]?
@connection = ::Redis.new(url: url)
elsif url = ENV["REDIS_URL"]?
@connection = ::Redis.new(url: url)
else
@connection = ::Redis.new
@@ -1,7 +1,7 @@
module Mosquito::Serializers::Granite
macro serialize_granite_model(klass)
{%
method_suffix = klass.stringify.underscore.gsub(/::/,"__").id
method_suffix = klass.stringify.underscore.gsub(/::/, "__").id
%}
def serialize_{{ method_suffix }}(model : {{ klass.id }}) : String
model.id.to_s
@@ -29,24 +29,23 @@ module Mosquito::Serializers::Primitives

{% begin %}
{%
primitives = [
{ Int8, :to_i8 },
{ Int16, :to_i16 },
{ Int32, :to_i32 },
{ Int64, :to_i64 },
{ Int128, :to_i128 },
primitives = [
{Int8, :to_i8},
{Int16, :to_i16},
{Int32, :to_i32},
{Int64, :to_i64},
{Int128, :to_i128},

{ UInt8, :to_u8 },
{ UInt16, :to_u16 },
{ UInt32, :to_u32 },
{ UInt64, :to_u64 },
{ UInt128, :to_u128 },
{UInt8, :to_u8},
{UInt16, :to_u16},
{UInt32, :to_u32},
{UInt64, :to_u64},
{UInt128, :to_u128},

{ Float32, :to_f32 },
{ Float64, :to_f64 }
]

%}
{Float32, :to_f32},
{Float64, :to_f64},
]
%}
{% for mapping in primitives %}

{%
@@ -1,3 +1,3 @@
module Mosquito
VERSION = "0.5.0"
VERSION = "0.6.0"
end
@@ -8,7 +8,6 @@ module Mosquito
@@mapping = {} of String => Job.class

yield

ensure
@@mapping = mapping unless mapping.nil?
@@scheduled_tasks = scheduled_tasks unless scheduled_tasks.nil?
@@ -19,10 +18,8 @@ module Mosquito
@@logger = Logger.new(STDOUT)

yield

ensure
@@logger = logger unless logger.nil?
end
end
end

@@ -4,7 +4,7 @@ describe Mosquito::Redis do
let(:data) {
{
"question" => "unknown",
"answer" => "forty-two"
"answer" => "forty-two",
}
}

@@ -19,7 +19,7 @@ describe "Mosquito::Runner#run_at_most" do
count = 0
moment = Time.utc
runner
incrementy = ->() do
incrementy = ->do
runner.yield_once_a_second do
count += 1
end
@@ -1,3 +1,2 @@
require "../test_helper"
require "./runner/*"

@@ -9,7 +9,7 @@ describe "task rescheduling" do
1 => 2,
2 => 8,
3 => 18,
4 => 32
4 => 32,
}

intervals.each do |count, delay|
@@ -20,7 +20,7 @@ describe "task rescheduling" do
end

it "prevents rescheduling a job too many times" do
run_task = -> do
run_task = ->do
task = Mosquito::Task.retrieve(failing_task.id.not_nil!).not_nil!
task.run
task
@@ -6,7 +6,7 @@ describe "task storage" do
let(:config) {
{
"year" => "1752",
"name" => "the year september lost 12 days"
"name" => "the year september lost 12 days",
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.