Commit 56d67fde by Ngô Trung Hưng

manager cronjob

parent 2b9b13bc
Pipeline #1119 failed with stages
in 0 seconds
# 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/
// Place all the styles related to the settings controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
.box_settings_w {
width: 100%;
margin-top: 25px;
}
.nav_menu_settings {
border-right: 1px solid #666;
ul {
padding-left: 0;
margin-bottom: 0;
list-style: none;
li {
padding: 10px 0;
a {
cursor: pointer;
text-decoration: none;
color: #333;
&:hover {
text-decoration: none;
color: #666;
}
}
a.is_active {
color: #000;
font-weight: bold;
}
}
}
}
table tr th {
&:nth-child(2), &:nth-child(3) {
text-align: center;
}
}
.tbody_custom {
td {
padding: 8px 12px;
span { line-height: 40px; }
&:nth-child(2), &:nth-child(3) {
text-align: center;
}
}
}
\ No newline at end of file
......@@ -3,7 +3,7 @@
# Admin controller
class Admin::AdminController < ApplicationController
before_action :authenticate_admin!, only: %s(index search export_csv)
before_action :authenticate_admin!
before_action :load_data_dropdown
include InitApply
......
class Admin::SettingsController < ApplicationController
before_action :authenticate_admin!
before_action :get_list_cronjob
def index; end
def cron_implement
tmp = File.open(eval(Settings.path_schedule_tmp), 'w')
File.foreach(eval(Settings.path_schedule)) do |line|
params[:code_action] == 'off' ? line.insert(0, '#') : line.delete!('#') if line.include?(params[:code_cron])
tmp << line
end
tmp.close
write_schedule(tmp)
CronJob.set(wait: 5.seconds).perform_later
return redirect_to settings_path
end
private
def write_schedule(txt)
File.truncate(eval(Settings.path_schedule), 0)
File.foreach(txt) do |line|
File.write(eval(Settings.path_schedule), line, mode: 'a')
end
end
def get_list_cronjob
@data_file_schedule = File.read(Rails.root.join('config', 'schedule.rb'))
@list_cronjob = @data_file_schedule.scan /(#?\s*?rake\s'.*?')/
end
end
class SettingDecorator < Draper::Decorator
delegate_all
# Define presentation-specific methods here. Helpers are accessed through
# `helpers` (aka `h`). You can override attributes, for example:
#
# def created_at
# helpers.content_tag :span, class: 'time' do
# object.created_at.strftime("%a %m/%d/%y")
# end
# end
end
module SettingsHelper
end
class CronJob < ApplicationJob
queue_as :default
def perform
system("whenever --update")
end
end
\ No newline at end of file
<% provide(:title, 'Settings') %>
<div class="box_settings_w">
<div class="container">
<h3 class="title_setting">Settings</h3><hr>
<div class="row">
<div class="col-lg-2">
<div class="nav_menu_settings">
<ul>
<li>
<%= link_to 'Crontab', '#', class: 'is_active'%>
</li>
<li>
<%= link_to 'Themes', '#' %>
</li>
</ul>
</div>
</div>
<div class="col-lg-10">
<table class="table table-dark">
<thead>
<tr>
<th scope="col">Cronjob</th>
<th scope="col">Status</th>
<th scope="col">Handler</th>
</tr>
</thead>
<tbody class="tbody_custom">
<% @list_cronjob.each do |cjob| %>
<% code = cjob.join.match("\'(.*)\'")[1] %>
<tr>
<td><span><%= code %></span></td>
<td><span><b><%= cjob.join.include?('#') ? 'OFF' : 'ACTIVE' %></b></span></td>
<td>
<%= link_to_if(cjob.join.include?('#'), 'On', settings_cron_path(code_cron: code, code_action: 'on'), method: :post, class: 'btn btn-primary btn-on btn-hi') do
link_to 'Off', settings_cron_path(code_cron: code, code_action: 'off'), method: :post, class: 'btn btn-danger btn-off btn-hi'
end %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
</div>
<%= render 'shared/loading_2' %>
<script>
$('.btn-hi').click(function (e) {
e.preventDefault();
$('.box_loading_2').css('display', 'block')
});
</script>
\ No newline at end of file
<style>
.box_loading_2 {
display: none;
z-index: 9999999;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
box-sizing: border-box;
background-image: linear-gradient(#fff, #fff);
}
.gif_loading {
position: relative;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
}
</style>
<div class="box_loading_2">
<%= image_tag 'load_3.gif', class: 'gif_loading' %>
</div>
......@@ -5,7 +5,9 @@ Rails.application.routes.draw do
scope '(:locale)', locale: /en|vi/ do
devise_for :users, controllers: { registrations: 'registrations' }
devise_for :admins, path: 'admin', path_names: { sign_in: 'login', sign_out: 'logout'}
root 'home#index'
get 'admin/setting', to: 'admin/settings#index', as: :settings
post 'admin/setting/cronjob/:code_cron/:code_action', to: 'admin/settings#cron_implement', as: :settings_cron
get 'admin/search', to: 'admin/admin#search', as: :applies
get 'admin/applies', to: 'admin/admin#index', as: :applies_index
......@@ -13,7 +15,7 @@ Rails.application.routes.draw do
get 'info/user/:user_id', to: 'users#personal_page', as: :personal_page
devise_for :users, controllers: { registrations: 'registrations', passwords: 'passwords'}
# devise_for :users, controllers: { registrations: 'registrations', passwords: 'passwords'}
root 'home#index'
# Search
get 'search', to: 'search#search', as: :searches
......
# Use this file to easily define all of your cron jobs.
#
# It's helpful, but not entirely necessary to understand cron before proceeding.
# http://en.wikipedia.org/wiki/Cron
require_relative 'environment'
# Example:
#
# set :output, "/path/to/my/cron_log.log"
#
# every 2.hours do
# command "/usr/bin/some_great_command"
# runner "MyModel.some_method"
# rake "some:great:rake:task"
# end
#
# every 4.days do
# runner "AnotherModel.prune_old_records"
# end
set :output, "log/cron.log"
# Learn more: http://github.com/javan/whenever
env :PATH, ENV['PATH']
set :environment, Rails.env || 'production'
every 1.hours do
rake 'crawler:populate', environment: 'development'
# rake 'crawler:populate'
end
every 1.minute do
rake 'advertise:send_email'
end
every 30.minute do
rake 'advertise:send_email', environment: 'development'
every 1.day, at: '2:30 am' do
# rake 'csv:import_csv'
end
number_result_search_in_page: 10
path_schedule: Rails.root.join('config', 'schedule.rb')
path_schedule_tmp: Rails.root.join('tmp', 'schedule.txt')
module Searches
class Query
class Searches::Query
def search(params)
solr = connect_solr
# Escape input & Convert space to asterisks
......@@ -28,5 +28,4 @@ module Searches
def connect_solr
SolrSetting::SolrServer.connection
end
end
end
# frozen_string_literal: true
namespace :manager do
task crontab: :environment do
command 'crontab -l'
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment