-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'f-add_auto_process_bot' into develop
- Loading branch information
Showing
34 changed files
with
577 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the S1tyles controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
class ContentsController < ApplicationController | ||
before_action :set_content, only: [:show, :edit, :update, :destroy] | ||
|
||
# GET /contents | ||
# GET /contents.json | ||
def index | ||
@contents = Content.all.order('created_at DESC') | ||
end | ||
|
||
# GET /contents/1 | ||
# GET /contents/1.json | ||
def show | ||
end | ||
|
||
# GET /contents/new | ||
def new | ||
@content = Content.new | ||
end | ||
|
||
# GET /contents/1/edit | ||
def edit | ||
end | ||
|
||
# POST /contents | ||
# POST /contents.json | ||
def create | ||
@content = Content.new(content_params) | ||
|
||
respond_to do |format| | ||
if @content.save | ||
format.html { redirect_to @content, notice: 'content was successfully created.' } | ||
format.json { render :show, status: :created, location: @content } | ||
else | ||
format.html { render :new } | ||
format.json { render json: @content.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /contents/1 | ||
# PATCH/PUT /contents/1.json | ||
def update | ||
respond_to do |format| | ||
if @content.update(content_params) | ||
format.html { redirect_to @content, notice: 'content was successfully updated.' } | ||
format.json { render :show, status: :ok, location: @content } | ||
else | ||
format.html { render :edit } | ||
format.json { render json: @content.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /contents/1 | ||
# DELETE /contents/1.json | ||
def destroy | ||
@content.destroy | ||
respond_to do |format| | ||
format.html { redirect_to contents_url, notice: 'content was successfully destroyed.' } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_content | ||
@content = Content.find(params[:id]) | ||
end | ||
|
||
# Never trust parameters from the scary internet, only allow the white list through. | ||
def content_params | ||
params.require(:content).permit(:image, :init, :status, :use_counter) | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
class StylesController < ApplicationController | ||
before_action :set_style, only: [:show, :edit, :update, :destroy] | ||
|
||
# GET /styles | ||
# GET /styles.json | ||
def index | ||
@styles = Style.all.order('created_at DESC') | ||
end | ||
|
||
# GET /styles/1 | ||
# GET /styles/1.json | ||
def show | ||
end | ||
|
||
# GET /styles/new | ||
def new | ||
@style = Style.new | ||
end | ||
|
||
# GET /styles/1/edit | ||
def edit | ||
end | ||
|
||
# POST /styles | ||
# POST /styles.json | ||
def create | ||
@style = Style.new(style_params) | ||
|
||
respond_to do |format| | ||
if @style.save | ||
format.html { redirect_to @style, notice: 'style was successfully created.' } | ||
format.json { render :show, status: :created, location: @style } | ||
else | ||
format.html { render :new } | ||
format.json { render json: @style.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /styles/1 | ||
# PATCH/PUT /styles/1.json | ||
def update | ||
respond_to do |format| | ||
if @style.update(style_params) | ||
format.html { redirect_to @style, notice: 'style was successfully updated.' } | ||
format.json { render :show, status: :ok, location: @style } | ||
else | ||
format.html { render :edit } | ||
format.json { render json: @style.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /styles/1 | ||
# DELETE /styles/1.json | ||
def destroy | ||
@style.destroy | ||
respond_to do |format| | ||
format.html { redirect_to styles_url, notice: 'style was successfully destroyed.' } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_style | ||
@style = Style.find(params[:id]) | ||
end | ||
|
||
# Never trust parameters from the scary internet, only allow the white list through. | ||
def style_params | ||
params.require(:style).permit(:image, :init, :status, :use_counter) | ||
end | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module StylesHelper | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
class BotJob | ||
include DebHelper | ||
include ConstHelper | ||
include WorkerHelper | ||
|
||
|
||
def initialize | ||
@worker_name = :bot1 | ||
@admin_email = "cmorugin@gmail.com" | ||
end | ||
|
||
|
||
|
||
def execute | ||
|
||
log('-----------------------Start-------------------') | ||
adm = Client.find_by(email: @admin_email) | ||
log("Admin_id = #{adm.id}") | ||
loop do | ||
sleep 10 | ||
log('------Loop start-------') | ||
if !check_idle | ||
log("Queue busy") | ||
next | ||
end | ||
ci = get_random_content | ||
if ci.nil? | ||
log("No content") | ||
next | ||
end | ||
si = get_random_style | ||
if si.nil? | ||
log("No style") | ||
next | ||
end | ||
log("Content: #{ci.attributes}") | ||
log("Style: #{si.attributes}") | ||
qi = QueueImage.new | ||
qi.status = STATUS_NOT_PROCESSED | ||
qi.end_status = STATUS_VISIBLE_FOR_BOT | ||
qi.content_id = ci.id | ||
qi.style_id = si.id | ||
|
||
qi.client_id = adm.id | ||
qi.save | ||
|
||
start_workers | ||
log("Queue: #{qi.attributes}") | ||
log('----------Loop stop----------') | ||
# | ||
#break | ||
end | ||
end | ||
|
||
private | ||
|
||
def check_idle | ||
q = QueueImage.where("status = #{STATUS_NOT_PROCESSED} or status = #{STATUS_IN_PROCESS}") | ||
q.count == 0 | ||
end | ||
|
||
def get_random_style | ||
si = Style.where(status: BOT_STYLE_IMAGE) | ||
count = si.count | ||
return nil if count == 0 | ||
r = rand(count) | ||
si[r] | ||
end | ||
|
||
def get_random_content | ||
ci = Content.where(status: BOT_CONTENT_IMAGE) | ||
count = ci.count | ||
return nil if count == 0 | ||
r = rand(count) | ||
ci[r] | ||
end | ||
|
||
def log(msg) | ||
write_log(msg, @worker_name.to_s) | ||
end | ||
|
||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class BotResqueJob | ||
@queue = :job1 | ||
|
||
def initialize | ||
|
||
end | ||
|
||
def self.perform(*arg) | ||
#return false if arg.blank? || arg[0].blank? | ||
|
||
bot_job = BotJob.new | ||
bot_job.execute | ||
end | ||
|
||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
<h1>AdminPages#main</h1> | ||
<p>Find me in app/views/admin_pages/main.html.erb</p> | ||
<p><%= link_to 'Очередь ', admin_pages_images_path %><p/> | ||
<p><%= link_to 'Contents', contents_path %><p/> | ||
<p><%= link_to 'Styles', styles_path %><p/> | ||
<p><%= link_to 'Start bot', admin_pages_startbot_path %><p/> | ||
<p><%= link_to 'Start process', admin_pages_startprocess_path %><p/> |
Oops, something went wrong.