-
-
Save radar/4b1a87d9e1a38e680dc9b2c03a42f364 to your computer and use it in GitHub Desktop.
Trying to get a Back Job working
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fetchs campaigns from SiB | |
class CampaignFetch | |
def get | |
def sib | |
@sib ||= Mailin.new("API_URL","API_KEY") | |
end | |
def shoot_criteria | |
{ "type"=>"classic", "status" => "sent", "page"=>10,"page_limit"=>1000 } | |
end | |
def shoots | |
@shoots ||= sib.get_campaigns_v2(shoot_criteria) | |
end | |
def needed_records | |
first_cut = shoots.dig('data') | |
final_cut = first_cut.dig('campaign_records') | |
end | |
def campaign_records | |
@campaign_records ||= needed_records.map | |
end | |
# update/create | |
campaign_records.each do |record| | |
shoot = SibCampaign.find_or_create_by(:campaign_id => record["id"]) | |
unless shoot.update(record) | |
# the data was invalid, so the shoot wasn't saved, do something about that here | |
end | |
end | |
end | |
end | |
def sib_campaigns_fetch | |
CampaignFetch.new.delay.get | |
flash[:notice] = "Shoots imported from SendinBlue successfully." | |
redirect_to(:controller => 'campaign', :action => 'refresh') | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11:50:59 AM worker.1 | [Worker(host:crova pid:7085)] Starting job worker | |
11:50:59 AM worker.1 | [Worker(host:crova pid:7085)] Job CampaignController::CampaignFetch#get (id=17) RUNNING | |
11:50:59 AM worker.1 | [Worker(host:crova pid:7085)] Job CampaignController::CampaignFetch#get (id=17) FAILED (2 prior attempts) with TypeError: no implicit conversion of String into Integer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fetchs SIB Campaigns | |
def sib_campaigns_fetch | |
# update/create | |
campaign_records.each do |record| | |
shoot = SibCampaign.find_or_create_by(:campaign_id => record["id"]) | |
unless shoot.update(record) | |
# the data was invalid, so the shoot wasn't saved, do something about that here | |
end | |
end | |
campaign_records2.each do |record| | |
shoot2 = SibCampaign.find_or_create_by(:campaign_id => record["id"]) | |
unless shoot2.update(record) | |
# the data was invalid, so the shoot wasn't saved, do something about that here | |
end | |
end | |
flash[:notice] = "Shoots updated successfully." | |
redirect_to(:controller => 'campaign', :action => 'refresh') | |
end | |
def sib | |
@sib ||= Mailin.new("API_URL","API_KEY") | |
end | |
def shoot_criteria | |
{ "type"=>"classic", "status" => "sent", "page"=>1, "page_limit"=>1000 } | |
end | |
def shoot_criteria2 | |
{ "type"=>"classic", "status" => "sent", "page"=>2, "page_limit"=>1000 } | |
end | |
def shoots | |
@shoots ||= sib.get_campaigns_v2(shoot_criteria) | |
end | |
def shoots2 | |
@shoots2 ||= sib.get_campaigns_v2(shoot_criteria2) | |
end | |
def needed_records | |
first_cut = shoots.dig('data') | |
final_cut = first_cut.dig('campaign_records') | |
end | |
def needed_records2 | |
first_cut2 = shoots2.dig('data') | |
final_cut2 = first_cut2.dig('campaign_records') | |
end | |
def campaign_records | |
@campaign_records ||= needed_records.map | |
end | |
def campaign_records2 | |
@campaign_records2 ||= needed_records2.map | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment