How to use the slugid.encode function in slugid

To help you get started, we’ve selected a few slugid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github taskcluster / mozilla-taskcluster / src / treeherder / action_handler.js View on Github external
async handleAction(message) {
    let { payload, exchange, routes } = message;
    // We encode the task id/run into the job guid so extract the task id.
    let [taskId, runId] = payload.job_guid.split('/')
    taskId = slugid.encode(taskId);
    console.log(`Received ${payload.action} event for task ${taskId} by ${payload.requester}`);
    let task = await this.queue.task(taskId);

    switch (payload.action) {
      case 'cancel':
        await this.handleCancel(taskId, runId, task, payload);
        break;
      case 'retrigger':
        await this.handleRetrigger(taskId, runId, task, payload);
        break;
      default:
        console.log(`[action handler] unknown action ${payload.action}`);
    }
  }
}
github taskcluster / taskcluster / services / queue / queue / taskstore.js View on Github external
return rows.reduce(function(tasks, row) {
    // extract the task by task id (only create one)
    var taskId = slugid.encode(row.taskId);

    var task = byTaskId[taskId];
    if (!task) {
      task = byTaskId[taskId] = mapTask(taskId, row);
      tasks.push(task);
    }

    if (row.runId) {
      task.runs.push(mapRun(row));
    }

    return tasks;
  }, []);
}
github taskcluster / taskcluster / services / queue / queue / task.js View on Github external
.then(function(rows) {
      // Return 204, if no rows are available
      if (rows.length === 0) {
        return {
          code:     204,
          message:  "No runs pending for given provisionerId and workerType"
        };
      }
      var row = rows[0];
      // Claim the run and be done with it
      return that.claimTaskRun(
        slugid.encode(row.taskId),
        row.runId,
        options,
        knex
      );
    });
});
github taskcluster / taskcluster / services / auth / auth / data.js View on Github external
}
  if (type == 'json') {
    return JSON.parse(value);
  }
  if (type == 'date') {
    assert(
      value instanceof Date,
      "Value '" + value + "' must be an instance of Date object for " +
      "key " + entry.key
    );
    return value;
  }
  if (type == 'slugid') {
    assert(typeof(value) == 'string', "Slugids should be returned from " +
           "azure as strings");
    return slugid.encode(value);
  }
  debug("Entry with unknown type: ", entry);
  throw new Error("Can't deserialize unknown type: '" + type + "' for " +
                  "key: '" + entry.key + "'!");
};
github taskcluster / taskcluster / services / queue / queue / task.js View on Github external
.then(function(count) {
              if (count === 0) {
                debug("Failed to delete task %s in moveTaskFromDatabase",
                      slugid.encode(task.taskId));
              }
            });
        });
github taskcluster / taskcluster / services / queue / queue / task.js View on Github external
this.runs.forEach(function(run) {
    run.taskId = slugid.encode(run.taskId);
  });
};
github taskcluster / azure-entities / src / entitytypes.js View on Github external
SlugIdType.prototype.deserialize = function(source) {
  return slugid.encode(source[this.property]);
};
github taskcluster / taskcluster / services / queue / queue / task.js View on Github external
var Task = function(rowInfo) {
  _.assign(this, rowInfo.taskRow);
  this.taskId       = slugid.encode(this.taskId);
  this.taskGroupId  = slugid.encode(this.taskGroupId);
  this.routes       = JSON.parse(this.routes);
  this.runs         = _.sortBy(rowInfo.runRows, 'runId');
  this.runs.forEach(function(run) {
    run.taskId = slugid.encode(run.taskId);
  });
};
github taskcluster / taskcluster / libraries / app / entity.js View on Github external
deserialize:  function(r) {
    assert.equal(typeof(r), 'string', "Slugids should be returned from " +
                                      "azure as strings");
    return slugid.encode(r);
  }
});

slugid

URL-safe base64 UUID encoder for generating 22 character slugs

MIT
Latest version published 5 months ago

Package Health Score

82 / 100
Full package analysis