小编sal*_*lep的帖子

如何确保工作不会在 Bull 中运行两次?

我有两个功能,scheduleScan()scan().

scan()scheduleScan() 除了安排新的扫描之外别无他事时调用,因此scheduleScan()可以安排scan(). 但是有一个问题,有些作业会运行两次。

我想确保在任何给定时间只处理一项作业。我怎样才能做到这一点?我相信它与done(), (它在 scan() 中,现在已删除)有关,但我想不出解决方案。

公牛版本:3.12.1

重要的后期编辑: scan()调用另一个函数,他们可能会也可能不会调用其他函数,但它们都是同步函数,所以它们只在自己的工作完成时调用一个函数,只有一种方法。在“树”的末尾,我调用它,最后一个函数调用 scheduleScan(),但不能同时运行两个作业。scan()顺便说一下,每个工作都以 开始,并以scheduleScan(stock, period, milliseconds, 'called by file.js')

export function update(job) {
  // does some calculations, then it may call scheduleScan() or
  // it may call another function, and that could be the one calling
  // scheduleScan() function.
  // For instance, a function like finalize()
}

export function scan(job) {
  update(job)
}


import moment …
Run Code Online (Sandbox Code Playgroud)

javascript node.js bull.js

14
推荐指数
2
解决办法
1894
查看次数

Laravel未定义函数内的变量

$id从网址获取了我,但我找不到在函数中使用它的方法.如何将$ id传递给查询函数?

我尝试了全局$ id,但我仍然无法得到一个值,只是空页.

我的控制器.

class BookController extends Controller
{
    public function bookIndex($id, $slug)
    {
     // echo $id works without a problem
     $findcover = Thing::with(array('cover' => function($query) {
                $query->where('imageable_type', 'App\Models\Thing')
                  ->where('imageable_id', $id);
            }))->find($id);

            $maincover = $findcover->cover;
}
Run Code Online (Sandbox Code Playgroud)

错误:

ErrorException in BookController.php line 49:
Undefined variable: id
Run Code Online (Sandbox Code Playgroud)

第49行

->where('imageable_id', $id);
Run Code Online (Sandbox Code Playgroud)

php eloquent laravel-5.1

9
推荐指数
1
解决办法
5062
查看次数

Laravel 5.1:迁移现有数据库

https://github.com/Xethron/migrations-generator

php artisan migrate:generate在上面的扩展的帮助下使用命令将我的数据库结构迁移到Laravel .但是有一个小问题,我的主键没有被命名为id,我宁愿使用不同的约定,为每个人添加一个前缀,如user_id,product_id,photo_id等.当然,所有这些都是自动递增的.

这是我的迁移文件夹中的当前create_users_table.php文件.我定义了user_id来覆盖默认的id选项,这是正确的用法吗?

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateUsersTable extends Migration
{

/**
 * Run the migrations.
 *
 * @return void
 */
    public function up()
{
    Schema::create('users', function (Blueprint $table) {
          $table->primary('user_id');
          $table->integer('user_id', true);
          $table->string('name', 500);
          $table->string('email', 500);
          $table->string('password', 500);
      }
    );
}


/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::drop('users');
}
}
Run Code Online (Sandbox Code Playgroud)

我读到我需要添加类似下面的内容,但我不确定在哪里定义,protected $primaryKey因为我的类扩展了Migration而不是Eloquent.

class CreateUsersTable extends Eloquent {

    protected $primaryKey = 'user_id';

} …
Run Code Online (Sandbox Code Playgroud)

laravel eloquent laravel-5.1

7
推荐指数
1
解决办法
3488
查看次数

快速CSRF令牌验证

我遇到了CSRF令牌问题.当我提交表单时,XSRF-TOKEN会生成一个新表单,但我认为我正在生成两个不同的令牌,我有点困惑.还有一个令牌_csrf,所以我在开发者工具(XSRF-TOKEN和_csrf)中看到两个不同的cookie,在_csrf帖子后没有变化.

我想要做的是为每个帖子请求生成一个新令牌,并检查它是否有效.有一点我知道我应该为了安全而做,但我坚持了.

这是漫长的一天,我是Express和NodeJS的新手.

这是我目前的设置.

var express = require('express')
  , passport = require('passport')
  , flash = require('connect-flash')
  , utils = require('./utils')
  , csrf = require('csurf')
  // setup route middlewares
  ,csrfProtection = csrf({ cookie: true })
  , methodOverride = require('method-override')
  , bodyParser = require("body-parser")
  , parseForm = bodyParser.urlencoded({ extended: false })
  , cookieParser = require('cookie-parser')
  , cookieSession = require('cookie-session')
  , LocalStrategy = require('passport-local').Strategy
  , RememberMeStrategy = require('../..').Strategy;


var app = express();

app.set('views', __dirname + '/views');
app.set('view …
Run Code Online (Sandbox Code Playgroud)

csrf node.js csrf-protection express

7
推荐指数
1
解决办法
2万
查看次数

sequelize .create不是函数错误

我收到Unhandled rejection TypeError: feed.create is not a function错误,我无法理解为什么会发生错误.这有什么问题?

这是我的代码.因为我无法在routes/index.js中找到feed变量,所以我可能不会在这里做一些非常基本的事情.

如果我添加module.exports = feed; 到我的模型文件,我可以达到它,但我有多个模型,所以如果我在Feed下面添加其他模型,它们会覆盖它.

db.js

var Sequelize = require('sequelize');
var sequelize = new Sequelize('mydatabase', 'root', 'root', {
    host: 'localhost',
    dialect: 'mysql',
    port: 8889,

    pool: {
        max: 5,
        min: 0,
        idle: 10000
    },
    define: {
        timestamps: false
    }
});

var db = {};
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;
Run Code Online (Sandbox Code Playgroud)

models.js

var db = require('./db'),
    sequelize = db.sequelize,
    Sequelize = db.Sequelize;

var feed = sequelize.define('feeds', {
    subscriber_id: Sequelize.INTEGER, …
Run Code Online (Sandbox Code Playgroud)

node.js express sequelize.js

7
推荐指数
2
解决办法
1万
查看次数

Sequelize - 无法读取undefined的属性'define'

我正在尝试使用sequelize将记录插入MYSQL表.

安装了sequelize和mysql.

npm install --save sequelize

npm install --save mysql
Run Code Online (Sandbox Code Playgroud)

在app.js中定义它

var Sequelize = require('sequelize');
Run Code Online (Sandbox Code Playgroud)

db.js

var Sequelize = require('sequelize');

var sequelize = new Sequelize('randomdb', 'root', 'root', {
    host: 'localhost',
    dialect: 'mysql',
    port : 8889,

    pool: {
        max: 5,
        min: 0,
        idle: 10000
    }
});

exports.sequelize = sequelize;
module.exports = Sequelize;
Run Code Online (Sandbox Code Playgroud)

路线/ index.js

var express = require('express');
var router = express.Router();
var sequelize = require('../db').sequelize;

/* GET home page. */
router.get('/', function (req, res, next) {
    res.render('index', {title: 'Express'});
}); …
Run Code Online (Sandbox Code Playgroud)

node.js express sequelize.js

6
推荐指数
1
解决办法
2万
查看次数

有没有办法让WebStorm自动完成标签属性值?

我正在尝试让WebStorm在使用Angular Material时自动完成一些HTML属性值.

编辑器>检查> HTML>未知的HTML标记属性

我喜欢这里增加了一些属性flex,flex-md以及layout,但我怎么能得到自动完成像下面的情况吗?

<div layout="can be row or column"></div>
Run Code Online (Sandbox Code Playgroud)

布局的值是a row或者column,所以当我输入layout ="row/column here"时,我想要显示行和列,是否可能?

我正在使用WebStorm 12 EAP.

webstorm

5
推荐指数
1
解决办法
328
查看次数

使用 pm2 的集群模块与 socket.io 和 socket.io-redis

我正在尝试使 pm2 集群模块与 socketio 一起工作,但是在访问 /hello 时出现错误。鉴于该集群使用了所有 CPU 内核,socketio 感到困惑,所以我安装了 socket.io-redis 模块来解决这个问题,但它看起来根本没有做任何与 Redis(它是空的)或 socket.io 相关的事情,我可能遗漏了一些非常明显的东西。

我使用 Nginx 作为 Web 服务器和我的快速服务器,localhost:8000 指向 localhost:80。

检查:

  • Nginx 工作,http://localhost/hello返回 socketio 的响应,我在浏览器控制台上看到它。

  • Redis 实例已开启

如果我在npm start不使用集群的情况下启动我的服务器,它会起作用,但sudo pm2 start bin/www -i 0会在问题的底部产生错误。

后端

这是我的 nginx.conf

user  myusernameishere staff;
worker_processes   1;

server {
    listen       80;
    server_name localhost;
    location / {
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_http_version 1.1;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $host;
      proxy_pass http://localhost:8000;
  }
}
Run Code Online (Sandbox Code Playgroud)

应用程序.js …

nginx node.js socket.io pm2

5
推荐指数
1
解决办法
1504
查看次数

不能在 C# 中将类型 void 隐式转换为对象错误

我在允许我使用自己的代码扩展其功能的应用程序中使用它。

它是用 C# 编码的。

Result()将返回它从我的 Node.js 服务器 ( FinalResponse)获得的答案,我将在如下所示的应用程序中访问它,但是当我尝试使用 EchoOut() 时,标题中出现错误。

var returnedValue = Lib.Result();
App.EchoOut(returnedValue); // EchoOut allows you to test the function you wrote, it echoes string on the screen, but in this case, it gives an error.
Run Code Online (Sandbox Code Playgroud)

错误

cannot implicitly convert type void to object 
Run Code Online (Sandbox Code Playgroud)

当我Lib.Result()单独测试时,我看到应用程序正在发出请求,但我无法将返回的值分配给变量。

如何将FinalResponse's值分配给returnedValue变量?

我的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace MainNameSpace
{
  public class Lib
  {
    public void …
Run Code Online (Sandbox Code Playgroud)

c#

5
推荐指数
1
解决办法
3万
查看次数

Fuse.js:当有两个词要搜索时如何返回完全匹配?

这就是我想要完成的。

Old War不应该匹配,但确实匹配。-> 这不是我要找的,即使有两个词,也必须完全匹配。Old Man是肯定的,但Old War不是。

Man's War应该匹配。此刻确实如此。

Silmarillion应该匹配。此刻确实如此。

The Silmarillion也应该匹配。此刻确实如此。

var express = require('express');
var router = express.Router();
var path = require("path");
var async1 = require("async");
var Fuse = require("fuse.js");

var options = {
  shouldSort: true,
  tokenize: true,
  matchAllTokens: true,
  findAllMatches: true,
  threshold: 0,
  location: 0,
  distance: 0,
  maxPatternLength: 32,
  minMatchCharLength: 2,
  keys: ["title"]
};


var arr = [
  {
    title: "Old Man's War",
    author: {
      firstName: "John",
      lastName: "Scalzi"
    } …
Run Code Online (Sandbox Code Playgroud)

node.js fuse.js

5
推荐指数
1
解决办法
3903
查看次数